{"size": 1673, "ext": "js", "max_stars_repo_path": "server.js", "max_stars_repo_name": "JoseEPina/challenge-tech-blog", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "server.js", "max_issues_repo_name": "JoseEPina/challenge-tech-blog", "max_issues_repo_issues_event_min_datetime": "2021-11-05T05:38:58.000Z", "max_issues_repo_issues_event_max_datetime": "2021-11-13T22:16:51.000Z", "max_forks_repo_path": "server.js", "max_forks_repo_name": "JoseEPina/challenge-tech-blog", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 13, "max_forks_count": null, "avg_line_length": 34.1428571429, "max_line_length": 108, "alphanum_fraction": 0.7023311417}
const express = require('express');
const routes = require('./controllers');
const sequelize = require('./config/connection');

const path = require('path'); // path module utility to work w/ file and directory paths
const helpers = require('./utils/helpers');

const app = express();
const PORT = process.env.PORT || 3001;

//* import new express module for img uploading
// const fileUpload = require('express-fileupload');

const session = require('express-session');
const SequelizeStore = require('connect-session-sequelize')(session.Store);
const sess = {
   secret: 'BC-JoseEPina',
   cookie: {
      expires: 300000, // 5 min session expiration
   },
   resave: false,
   saveUninitialized: true,
   store: new SequelizeStore({
      db: sequelize,
   }),
};

const exphbs = require('express-handlebars'); // to set up handlebars as the app's template engine of choice
const hbs = exphbs.create({ helpers }); // pass the helpers to the express handlebars method
app.engine('handlebars', hbs.engine); // sets express engine 'handlebars' from handlebars' engine
app.set('view engine', 'handlebars'); // sets 'view engine' from app.engine

// Middleware
app.use(session(sess));
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));

// * New Express FileUpload Middleware
// app.use(fileUpload()); // For future version. Will allow to upload images to posts.

// turn on routes LAST, after adding middle ware above.
app.use(routes);

// turn on connection to db and server
sequelize.sync({ force: false }).then(() => {
   app.listen(PORT, () => console.log(`Now listening at ${PORT}`));
});
