Back

HTTP Module

Node.js has a built-in HTTP module for creating servers. This is what Express builds on top of.

const http = require('http')

const server = http.createServer((req, res) => {
  if (req.url === '/') {
    res.writeHead(200, { 'Content-Type': 'application/json' })
    res.end(JSON.stringify({ message: 'Hello!' }))
  } else {
    res.writeHead(404)
    res.end('Not found')
  }
})

server.listen(3000, () => {
  console.log('Server running on port 3000')
})

Roadmap