The script of server.js which is the main entrypoint of your application.
constexpress=require('express');constbodyParser=require('body-parser');letapp=express();app.use(function(req,res,next){res.setHeader('Access-Control-Allow-Origin','http://localhost:5000');res.header("Access-Control-Allow-Headers","Origin, X-Requested-With, Content-Type, Accept");res.header('Access-Control-Allow-Methods','POST, GET, PUT, DELETE, OPTIONS');next();});app.use(bodyParser.urlencoded({extended: true}));app.use(bodyParser.json());app.use(bodyParser.raw());varport=process.env.PORT||5000;varApiRouter=require('../routes/main');app.use('',ApiRouter);app.listen(port);console.log('Server is running on port '+port);
Run your application
In VS Code, type [npm start] to start your server at http://localhost:5000. You can test the api using postam or other api tester.