Before we start off with use cases, we will need a base starting point in the form of a Node.js application. To create one, ensure that you have the latest Node.js installed:
node -v
This should show you your currently installed Node.js version; if it does not, then download and install the latest version of Node.js from https://nodejs.org/en.
To start off a sample Node.js project, simply create a project folder first and then run the following command from that folder:
npm init
On running this command, Node will prompt you with a series of questions, which you can either fill or leave blank:
Once the blank application is created, all you see is a file called package.json
. You can now add the dependencies that are needed to create the Node.js application:
npm install body-parser express --save
The body-parser
module helps with parsing of the POST request body, whereas the express
module helps with the creation of the Node.js server.