Advertisement
Mark1928

App.js backend

May 17th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require("path");
  2.  
  3. const express = require("express");
  4. const bodyParser = require("body-parser");
  5. const session = require("express-session");
  6. const flash = require("express-flash");
  7. require("dotenv").config();
  8. const cors = require("cors");
  9.  
  10. const sequelize = require("./util/db");
  11. const indexRoute = require("./routes/index");
  12. const errorController = require("./controllers/error");
  13.  
  14. const app = express();
  15.  
  16. app.set("view engine", "pug");
  17. app.use(
  18.   session({
  19.     cookie: { maxAge: 60000 },
  20.     secret: process.env.SESSION_SECRET,
  21.     resave: true,
  22.     saveUninitialized: false,
  23.   })
  24. );
  25. app.use(cors());
  26. app.use(flash());
  27. app.use(express.static(path.join(__dirname, "/public")));
  28. app.use(bodyParser.json());
  29. app.use(bodyParser.urlencoded({ extended: true }));
  30.  
  31. app.use(indexRoute);
  32. app.use(errorController.get404);
  33.  
  34. (async () => {
  35.   await sequelize.sync();
  36.   app.listen(3000, () => {
  37.     console.log("App is running at http://localhost:3000");
  38.   });
  39. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement