0% found this document useful (0 votes)
17 views

Create MOCK REST API With JSON Server

The document provides instructions for installing Node.js and JSON Server. It outlines downloading and running the Node.js installer, verifying the installation, and restarting the system. It then details creating a folder for the JSON Server project, initializing NPM, installing the JSON Server package, creating a JSON database file with sample data, adding a start script to the package.json file, and running the server to launch it on port 3000 using the JSON database file.

Uploaded by

Minh Hà Gia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Create MOCK REST API With JSON Server

The document provides instructions for installing Node.js and JSON Server. It outlines downloading and running the Node.js installer, verifying the installation, and restarting the system. It then details creating a folder for the JSON Server project, initializing NPM, installing the JSON Server package, creating a JSON database file with sample data, adding a start script to the package.json file, and running the server to launch it on port 3000 using the JSON database file.

Uploaded by

Minh Hà Gia
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

I. Installing Node.

js
1. Download the latest version of  Node.js Installer here.
2. Run the installer.
3. Follow the installer steps, and click the next button. Finally, click the Install button to run the
installer. When it finishes, click Finish.
4. Restart your system/machine.
5. At last, verify whether you have properly installed Node.js in your window, run the following
command in “Command Prompt”:

type node -v command, the system should display the Node.js version installed on your system.

type npm -v command, the system should display the NPM version installed on your system.

II. Installing JSON Server


1. Create a folder, for example: “d:\api-mocker”
2. Open “Node.js Command prompt”, and go to the folder by running command cd /d D:\ api-
mocker
3. Run command npm init , it will take a while to process, press Enter for everything. Finally, enter
‘yes’ for last step. It will create package.json file in your folder. (You are creating a new project
here)
4. Run command npm install json-server , this will install and add json-server as a package into your
project
5. Next step is creating a database file. You create a <file-name>.json that stores the data of the
mock database in JSON format. Let’s add some data to the file. For example, let’s name the file
mockerDB.json.
6. Open “package.json” file. In “scripts” key, add "start": "json-server --watch mockerDB.json"

7. Run command npm run start -- for starting the server, and it will load data from mockerDB.json

When it finished, you should have the Mock REST API running at http://localhost:3000

You might also like