Change The Default Port Number Of JSON-Server

In my previous blog we have seen how to create a REST API with JSON Server, if you missed please have a look at here Link

And whenever we start the JSON Server it is running on http://localhost:3000, mean its running in your localhost and the port number is 3000, In this blog we will see how to change the port number from 3000 to another port (xxxx) incase something you are running already on 3000

Please refer here how to setup the JSON Server on your machine - Link

Once we are done with the setup and if you want to start the JSON Server in different port then we have to run this command in terminal to start the JSON Server

Usually we use this command to start JSON Server which will run the server on 3000 port

json-server data.json


  • Start the JSON Server in different port

Instead of running the above command we have additionally pass the port parameter value to start in particular port as per your need

json-server -p 4000 data.json

And now you can open the URL in browser or Postman to check the server is connected and its up and running 



And you can monitor your server logs as well on the terminal


  • **Important - Do not close the server which we started from terminal until you preformed all actions, if you close the server the endpoints will not work further, and you can start the server again by following the same steps
  • Video Reference



Thanks
Saravanan Seenivasan
QA Lead Engineer



 

Comments

Popular posts from this blog

Create A REST API With JSON Server