Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

nodejs http

const http = require('http')

const server = http.createServer((req, res) => {
  if (req.url === '/') { //Home Page
    res.end('Welcome to our home page')
  } else if (req.url === '/about') { //About page
    res.end('Here is our short history')
  } else {
    res.end(`
    <h1>Oops!</h1>
    <p>We can't seem to find the page you are looking for</p>
    <a href="/">back home</a>
    `) // Page not found
  }
})

server.listen(5000)
console.log('Server is listening on port 5000')
 
PREVIOUS NEXT
Tagged: #nodejs #http
ADD COMMENT
Topic
Name
8+6 =