Project structure
The complete code for the backend server is available in CH07/server
. In this chapter, we are going to understand how the REST API can be built. Start with an empty folder and follow these steps:
- Initiate the project with
yarn init
or by creating apackage.json
file. We are already familiar with the process of adding and removing anynpm
packages from the project. Simply copy thepackage.json
file fromCH08
into your new project folder. - Create a folder called
server
where we can place all our backend logic. We are going to use theexpress
framework to create backend. Inside theserver
folder, create a file calledindex.js
. Inside the file, we initiate theexpress
server with the required parameter, as follows:
/* eslint consistent-return:0 import/order:0 */ const path = require('path'); const express = require('express'); const cookieParser = require('cookie-parser'); const methodOverride = require('method-override'); const session = require('express-session'); const bodyParser...