Table of contents
No headings in the article.
This app starts a server and listens on port 3000 for connections. The app responds with “Hello World!” for requests to the root URL (/) or route. For every other path, it will respond with a 404 Not Found.
Requirements to run this app:
- Have node already installed and setup. Download: nodejs.org/en/download
Install the express module using > npm install express --save.
Have a text editor. I'm using VS Code.🙂
const express = require('express')
const app = express()
const port = normalise(process.env.PORT || '3000')
app.set('port', port)
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(app.get('port'), () => {
console.log(`Example app listening on port ${app.get('port')}`)
})
Run the app with the following command:
node app.js
Then open your browser and go to localhost:3000