app.listen
Environment Variables
User Authentication
Passport.js
Controller
Routes
Views
User Model
When server.js is run, it checks to make sure the database is capable of running without errors, then calls app.listen. The server will not start if any errors are caught. The process will terminate and the errors will be logged to the console.
models.sequelize.sync().then(function () {
console.log('Nice! Database looks fine');
app.listen(PORT, function (error) {
if (error) {
throw Error(error);
}
console.log("Running @:", "http://localhost:" + PORT);
});
}).catch(function (err) {
console.log(err, "Something went wrong with the Database Update!");
});The dotenv is used to reference private data through the server's environment (process.env).
The app utilizes the Passport.js library to handle user authentication. The Passport config directory contains the logic for creating new users, encrypting passwords using the bcrypt package, signing in existing users and validating passwords, also using bcrypt.
The ./controllers/authctrl file is a set of methods that are exported to handle sign-up, sign-in, detecting if a user is signed-in, and logout.
In order to run, the routes module requires the following modules:
// Provide access to the Passport module
const authctrl = require('../controllers/authctrl.js');
const passport = require('passport');
// Provide access to the User moddle
var models = require("../models");The app uses Handlebars for the dashboard, sign-up and sign-in.
The User model holds the logic for creating and signing in users. The User model contains an ID (primary key), first and last name, email (the username), password, last login, and session status. This data is saved and persisted in the lead_generator database.