http module nodejs code example

Example 1: node http request

const https = require('https')
const options = {
  hostname: 'whatever.com',
  port: 443,
  path: '/todos',
  method: 'GET'
}

const req = https.request(options, res => {
  console.log(`statusCode: ${res.statusCode}`)

  res.on('data', d => {
    process.stdout.write(d)
  })
})

req.on('error', error => {
  console.error(error)
})

req.end()

Example 2: http module in nodejs

//HTTP MODULE NODE.JS
var http = require('http');
var server = http.createServer(function(req, res){
  //write code here
});
server.listen(5000);