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. When the questions ask you for the entry point, be sure to specify api.js
, since this is the main file that your server configuration will be read from.
Next, you will need to import the database interface module that we created in Chapter...