Firstly, create a file named server.js that will include two middleware functions. One that configures a session and the other that makes sure that there is a connection to the MongoDB before allowing any route to be called. Then, we mount our API routes to a specific path:
- Create a new file named server.js
- Include the required libraries. Then, initialize a new ExpressJS application and create a connection to MongoDB:
const mongoose = require('mongoose') const express = require('express') const session = require('express-session') const bodyParser = require('body-parser') const MongoStore = require('connect-mongo')(session) const api = require('./api/controller') const app = express() const db = mongoose.connect( 'mongodb://localhost:27017/test' ...