Exercise 41 - Setting Up A Server Using Json-Server
Exercise 41 - Setting Up A Server Using Json-Server
Exercise Resources
db.json
images.zip
Installing json-server
json-server is a node module, and hence can be installed globally by typing the following at the
command prompt:
If you are using OSX or Linux, use sudo at the front of the command. This will install json-server that
can be started from the command line from any folder on your computer.
This should start up a server at port number 3001 on your machine. The data from this server can
be accessed by typing the following addresses into your browser address bar:
http://localhost:3001/dishes
http://localhost:3001/promotions
1
http://localhost:3001/leaders
http://localhost:3001/feedback
Type these addresses into the browser address and see the JSON data being served up by the
server. This data is obtained from the db.json file
The json-server also provides a static web server. Any resources that you put in a folder named
public in the json-server folder above, will be served by the server at the following address:
http://localhost:3001/
http://localhost:3001/images/<image name>.png
Conclusions
In this exercise, you learnt how to configure and start a simple server using the json-server node
module. You also learnt how the server can serve up static web content.