Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to run curl in javascript

#Since javascript already has functions for this purpose
#so it is not advisable to load an extra library for that
#you can achieve the same in native javascript like this
var url = "http://www.google.com";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      console.log(xhr.status);
      console.log(xhr.responseText);
   }};

xhr.send();

#But still if you want to do it using curl in Node.js, it is possible
#Take a look at: https://github.com/JCMais/node-libcurl
var Curl = require( 'node-libcurl' ).Curl;

var curl = new Curl();

curl.setOpt( 'URL', 'http://www.google.com' );
curl.setOpt( 'FOLLOWLOCATION', true );

curl.on( 'end', function( statusCode, body, headers ) {

    console.info( statusCode );
    console.info( '---' );
    console.info( body.length );
    console.info( '---' );
    console.info( this.getInfo( 'TOTAL_TIME' ) );

    this.close();
});

curl.on( 'error', function ( err, errCode ) {

    //do something

    this.close();
});

curl.perform();

Comment

how to access curl data in javascript

var url = "www.yahoo.com";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      console.log(xhr.status);
      console.log(xhr.responseText);
   }};

xhr.send();
Comment

PREVIOUS NEXT
Code Example
Javascript :: timepicker in jquery 
Javascript :: how to count specific letters in string js 
Javascript :: react google map 
Javascript :: random number generator javascript with range 
Javascript :: $q.platform.is.mobile 
Javascript :: js + before variable 
Javascript :: find even numbers in an array javascript 
Javascript :: multiple case switch javascript 
Javascript :: javascript create element input type text 
Javascript :: remove all duplicates from an array 
Javascript :: js check if array of dictionaries contain 
Javascript :: ref focus not working vue js 
Javascript :: nvm check version available to download 
Javascript :: make input not editable for user js 
Javascript :: sort strings javascript alphabetically 
Javascript :: date get full year 
Javascript :: javascript json stringify indented 
Javascript :: javascript null or empty 
Javascript :: vue get if checkbox is checked 
Javascript :: regex find first instace 
Javascript :: mongodb data types 
Javascript :: how to get all the voice channels in discord js 
Javascript :: difference between library and framework in javascript 
Javascript :: js how to filter only real numbers from decimals 
Javascript :: remove part of string javascript 
Javascript :: date.parse string to javascript 
Javascript :: vuejs get value of checkbox group 
Javascript :: field array using useFormik 
Javascript :: javascript sort map by value 
Javascript :: how to send axios delete to the backend reactjs 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =