Skip to content

Instantly share code, notes, and snippets.

@srinivas69
Created June 18, 2020 16:27
Show Gist options
  • Save srinivas69/6e2593b03a9937dbf373d6cc0b5e041f to your computer and use it in GitHub Desktop.
Save srinivas69/6e2593b03a9937dbf373d6cc0b5e041f to your computer and use it in GitHub Desktop.
create nodejs server
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const app = express();
const port = 3000;
// configure middleware
app.set('port', process.env.port || port); // set express to use this port
app.set('views', __dirname + '/views'); // set express to look in this folder to render our view
app.set('view engine', 'ejs'); // configure template engine
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json()); // parse form data client
app.use(express.static(path.join(__dirname, 'public'))); // configure express to use public folder
// set the app to listen on the port
app.listen(port, () => {
console.log(`Server running on port: ${port}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment