Skip to content

Instantly share code, notes, and snippets.

@kiknaio
Created February 18, 2017 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kiknaio/f73a0696c11f7ca58fd6cc7111389a07 to your computer and use it in GitHub Desktop.
Save kiknaio/f73a0696c11f7ca58fd6cc7111389a07 to your computer and use it in GitHub Desktop.
How to make guestbook with Express.js (part 1)
const express = require('express');
const morgan = require('morgan');
const bodyParser = require('body-parser');
// Define port for the server
const PORT = 3000;
const app = express();
// Require routes
const routes = require('./routes/routes');
// Set Application views directory
app.set('view', __dirname + 'views');
// Set Application view engine
app.set('view engine', 'ejs');
// Use body-parser to parse incoming requests and get body of it
app.use(bodyParser.urlencoded({ extended: false }));
// Log every activity on the server
app.use(morgan('dev'));
// Use required routes
app.use('/', routes);
// Start server and listen to port 3000
app.listen(PORT, () => {
console.log(`Application is running on ${PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment