Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save robby-robby/f6e9aeafdeddfc42de99d1d329ef6fc5 to your computer and use it in GitHub Desktop.
Save robby-robby/f6e9aeafdeddfc42de99d1d329ef6fc5 to your computer and use it in GitHub Desktop.

User

give me a js code example of a hello world express app

Assistant

Here is a very simple example of a "Hello, World!" app written in Node.js using Express.js.

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})

This program will respond with "Hello World!" for requests to the root URL (/) or route. For every other path, it will respond with a 404 Not Found. The app starts a server and listens on port 3000 for connections.

You can execute the app by saving the file and running it with the command: node app.js. It will be listening at http://localhost:3000.

Remember to have Express installed by running: npm install express

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment