Building a RESTful API with Node.js

Now that we have covered the basics of REST, let's put it into practice and build an API for OrderBase, which was constructed in the previous chapter. If you have not done so already, please take a moment to review the code that we wrote there in order to make sure that you understand what happens between our API and the database in this example.

Setting up the RESTful API

Start with creating a workspace for our server. On your drive, create a folder named order_api, step into this folder, and create and execute the file named api.js. Finally, open a terminal and execute the following:

npm init

As we saw in the previous chapter, this will give you a few questions to answer in order to bootstrap the Node.js server. ...

Get Learning Node.js for Mobile Application Development now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.