Answers for "http module nodejs"

14

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()
Posted by: Guest on March-20-2020
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);
Posted by: Guest on January-13-2021
0

http module nodejs

var http = require('http');

//create a server object:
http.createServer(function (req, res) {
  res.write('Hello World!'); //write a response to the client
  res.end(); //end the response
}).listen(8080); //the server object listens on port 8080
Posted by: Guest on July-21-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language