import express from 'express'
import models from './models';
import bodyParser from 'body-parser';
import users from './routes/users';
import cookieParser from 'cookie-parser';
import cookieSession from 'cookie-session';
import engine from 'ejs-mate';
import sessions from './routes/sessions'
import methodOverride from 'method-override'

const app = express();

app.engine('ejs', engine);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

app.use(methodOverride('_method'))

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
	extended: true
}));
app.use(cookieParser('S3CR37'));
app.use(cookieSession({
	name:'session',
	keys: ['key1', 'key2']
}))
app.set('port', process.env.PORT || 3000);

app.locals.userId = null

app.get('/', (req, res) => {
	res.render('index', {userId: req.session.userId})
});

app.use('/users', users())
app.use('/sessions', sessions())


app.listen(app.get('port'), () => {
	console.log("listening on port " + app.get('port'));
});

import express from 'express'
import models from './models';
import bodyParser from 'body-parser';
import users from './routes/users';
import cookieParser from 'cookie-parser';
import cookieSession from 'cookie-session';
import engine from 'ejs-mate';
import sessions from './routes/sessions'
import methodOverride from 'method-override'

const app = express();

// temp front-end views
app.engine('ejs', engine);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');

app.use(methodOverride('_method'))

// Required middlewares
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
	extended: true
}));
app.use(cookieParser('S3CR37'));
app.use(cookieSession({
	name:'session',
	keys: ['key1', 'key2']
}))

//setting port
app.set('port', process.env.PORT || 3000);

app.locals.userId = null

//index page
app.get('/', (req, res) => {
	res.render('index', {userId: req.session.userId})
});

//other routes
app.use('/users', users())
app.use('/sessions', sessions())

//sync model and listen to server after promise for sync resolves
models.sequelize.sync().then(() => {
	app.listen(app.get('port'), () => {
		console.log("listening on port " + app.get('port'));
	});
})

Add comments for different parts of entry and updated server listener to be within sequelize sync callback
Add comments for different parts of entry and updated server listener to be within sequelize sync callback
