Created
June 18, 2020 16:27
-
-
Save srinivas69/6e2593b03a9937dbf373d6cc0b5e041f to your computer and use it in GitHub Desktop.
create nodejs server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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