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 initor by creating apackage.jsonfile. We are already familiar with the process of adding and removing anynpmpackages from the project. Simply copy thepackage.jsonfile fromCH08into your new project folder. - Create a folder called
serverwhere we can place all our backend logic. We are going to use theexpressframework to create backend. Inside theserverfolder, create a file calledindex.js. Inside the file, we initiate theexpressserver 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...