Skip to main content

Command Palette

Search for a command to run...

Creating a Basic Express App

Published
•1 min read•View as Markdown
Creating a Basic Express App
N

I am a developer from Nigeria. I am a tech enthusiast. I love coding in Python and JavaScript and well learning new things every day

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: https://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 http://localhost:3000