How to host json-server in azure How to host json-server in azure json json

How to host json-server in azure


Step to step to run json-server on Azure Web App:

  1. Open your browser and go to App Service Editor (https://<your-app-name>.scm.azurewebsites.net/dev/wwwroot/)

  2. Run the command in the Console (Ctrl+Shift+C)

    npm install json-server --save-dev
  3. Put all file/folder (db.json and public folder) into wwwroot folder

  4. Create a server.js with the following content

    const jsonServer = require('json-server')const server = jsonServer.create()const router = jsonServer.router('db.json')const middlewares = jsonServer.defaults()server.use(middlewares)server.use(router)server.listen(process.env.PORT, () => {  console.log('JSON Server is running')})
  5. Click Run (Ctrl+F5), this will generate web.config file automatically and open your website in the browser.

    enter image description here


You can use the following to quickly setup a mock service which can serve REST APIs off static JSON files.

json-server

Just install the NodeJS module ($npm install -g json-server). Populate a static json file in the format attached and then run the JSON server ($ json-server --watch db.json --port 3000)