Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

node js http request

// Importing https module
const http = require('http');
  
// Setting the configuration for
// the request
const options = {
    hostname: 'jsonplaceholder.typicode.com',
    path: '/posts',
    method: 'GET'
};
    
// Sending the request
const req = http.request(options, (res) => {
    let data = ''
     
    res.on('data', (chunk) => {
        data += chunk;
    });
    
    // Ending the response 
    res.on('end', () => {
        console.log('Body:', JSON.parse(data))
    });
       
}).on("error", (err) => {
    console.log("Error: ", err)
}).end()
Comment

request get response node js

var options = {
  host: 'www.google.com',
  port: 80,
  path: '/upload',
  method: 'POST'
};

var req = http.request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
  console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
});

req.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});

// write data to request body
req.write('data
');
req.write('data
');
req.end();
Comment

Get Request Node HTTP

const https = require('node:https');

https.get('https://encrypted.google.com/', (res) => {
  console.log('statusCode:', res.statusCode);
  console.log('headers:', res.headers);

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

}).on('error', (e) => {
  console.error(e);
});
Comment

PREVIOUS NEXT
Code Example
Javascript :: get blob from file javascript 
Javascript :: jest invalid or unexpected token 
Javascript :: compare objects 
Javascript :: string remove last two characters javascript 
Javascript :: append to map javascript 
Javascript :: add days to date javascript dd/mm/yyyy in input date 
Javascript :: js append to array 
Javascript :: convert set to array javascript 
Javascript :: owl timeout loop 
Javascript :: nevigate on button click in angular 
Javascript :: learn nestjs 
Javascript :: ckeditor get instance from textarea 
Javascript :: prevent duplicate entries in javascript array 
Javascript :: how to copy text from input through button click js 
Javascript :: react check internet connection 
Javascript :: xlsx to csv javascript 
Javascript :: js concatenate regex 
Javascript :: inherit javascript 
Javascript :: react hello world 
Javascript :: array as json 
Javascript :: ref in functional components 
Javascript :: how to get os theme value in javascript 
Javascript :: validate form on submit 
Javascript :: react style css image 
Javascript :: getting values for metaboxes in wordpress 
Javascript :: vue select first option default 
Javascript :: put new attribute on html tag using javascript 
Javascript :: sweet alert 2 react 
Javascript :: Get the url and parse or url.parse deprecated solved 
Javascript :: Uncaught (in promise) DOMException: Failed to load because no supported source was found. 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =