How to host json-server in azure
Step to step to run json-server on Azure Web App:
Open your browser and go to App Service Editor (
https://<your-app-name>.scm.azurewebsites.net/dev/wwwroot/
)Run the command in the Console (Ctrl+Shift+C)
npm install json-server --save-dev
Put all file/folder (
db.json
and public folder) into wwwroot folderCreate a
server.js
with the following contentconst 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')})
Click Run (Ctrl+F5), this will generate
web.config
file automatically and open your website in the browser.
You can use the following to quickly setup a mock service which can serve REST APIs off static JSON files.
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)