You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
mkdir <projectname>-mock-api
cd <projectname>-mock-api
Step 1: Create a node js project
npm init -y
Step 2: Install json server dependency
npm i json-server
Step 3: Create server.js
constjsonServer=require('json-server')constserver=jsonServer.create()constrouter=jsonServer.router('db.json')constmiddlewares=jsonServer.defaults()server.use(middlewares)server.use('/api',router)server.listen(process.env.PORT||5000,()=>{console.log('JSON Server is running')})
Step 4: Create db.json
{"articles": [{"id": 1,"title": "Example Article","content": "This is an example."},{"id": 2,"title": "Second Article","content": "This is also an example."},{"title": "Third Article","content": "Another example!","id": 3}]}