GithubHelp home page GithubHelp logo

Check server availability. about node-libcurl HOT 3 CLOSED

jcmais avatar jcmais commented on August 24, 2024
Check server availability.

from node-libcurl.

Comments (3)

JCMais avatar JCMais commented on August 24, 2024

If you use the Curl wrapper (async):

var Curl = require( 'node-libcurl' ).Curl,
    curl = new Curl(),
    url  = 'http://www.google.com',
    isAddressAvailable = false,
    statusCode;

curl.setOpt( Curl.option.URL, url );
curl.setOpt( Curl.option.CONNECTTIMEOUT, 5 ); // max of 5 seconds timeout to connect
curl.setOpt( Curl.option.FOLLOWLOCATION, true ); // follow redirects
curl.setOpt( Curl.option.NOBODY, true ); // just check the headers, ignore the response body

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

    isAddressAvailable = ( statusCode === 200 );
    this.close();
});

curl.on( 'error', function () {
    this.close();
});

curl.perform();

If you use the Easy handler (sync):

var Easy = require( 'node-libcurl' ).Easy,
    Curl = require( 'node-libcurl' ).Curl,
    url  = 'http://www.google.com',
    isAddressAvailable = false;

ch = new Easy();

ch.setOpt( Curl.option.URL, url );
ch.setOpt( Curl.option.CONNECTTIMEOUT, 5 ); // max of 5 seconds timeout to connect
ch.setOpt( Curl.option.FOLLOWLOCATION, true ); // follow redirects
ch.setOpt( Curl.option.NOBODY, true ); // just check the headers, ignore the response body

ret = ch.perform();
statusCode = ch.getInfo( Curl.info.RESPONSE_CODE );

ch.close();

isSiteAvailable = ( statusCode === 200 );

from node-libcurl.

gerasimvol avatar gerasimvol commented on August 24, 2024

Allready done it, but thanks for your responce. Nice module.

from node-libcurl.

JCMais avatar JCMais commented on August 24, 2024

No problem.

from node-libcurl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.