The app.js file serves as the main entrypoint for the TimeOff.Management application, configuring an Express.js server. It sets up the Handlebars view engine, database model access, session management, and authentication via Passport.js.
Key configuration details:
- View Engine: Uses Handlebars (
.hbs) with a main layout and custom helpers from ./lib/view/helpers. - Database: The database model is attached to the application object via
app.set('db_model', ...), allowing access to the Sequelize instance. - Authentication: Uses Passport.js for session-based authentication. It requires
createSessionMiddleware configured with the Sequelize database instance. - Middleware: Includes standard middleware for body parsing, cookies, static files, and custom middleware for injecting session/user data into template locals.
var app = express();
// View engine setup
var handlebars = require('express-handlebars').create({
defaultLayout : 'main',
extname : '.hbs',
helpers : require('./lib/view/helpers')(),
});
app.engine('.hbs', handlebars.engine);
app.set('view engine', '.hbs');
// Database model access
app.set('db_model', require('./lib/model/db'));
module.exports = app;