1const express = require("express");
2const bodyParser = require("body-parser");
3const cors = require("cors");
4
5const app = express();
6
7var corsOptions = {
8 origin: "http://localhost:8081"
9};
10
11app.use(cors(corsOptions));
12
13// parse requests of content-type - application/json
14app.use(bodyParser.json());
15
16// parse requests of content-type - application/x-www-form-urlencoded
17app.use(bodyParser.urlencoded({ extended: true }));
18
19// simple route
20app.get("/", (req, res) => {
21 res.json({ message: "Welcome to esparkinfo application." });
22});
23
24// set port, listen for requests
25const PORT = process.env.PORT || 8080;
26app.listen(PORT, () => {
27 console.log(`Server is running on port ${PORT}.`);
28});