Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

MaxySpark

@MaxySpark
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • What is the work of callback argument in NodeJs "module.exports"?
    M MaxySpark

    I’m learning nodeJS. I don’t know what is the purpose of

    callback

    argument in

    module.exports

    . It pretty much look like

    return

    and

    console.log

    here is my code

    var request = require('request');

    module.exports = function(location,callback) {

    var encodedUrl = encodeURIComponent(location);
    //set url
    var url = "http://api.openweathermap.org/data/2.5/weather?q="+encodedUrl+"&APPID=575991c6b55a139d32139652d78bc8b8&units=metric";
    

    //location check
    if(!location) {
    callback("No location provided");
    } else {
    callback('location is '+location);
    }

    //request
    request({
    url: url,
    json: true
    }, function (error,response, body) {
    if(error) {
    callback('Unable To Fetch Weather');
    } else {
    //console.log(JSON.stringify(body, null, 4));
    callback("Current Temperature in "+body.name+" "+body.main.temp + '\xB0!!!');
    }
    });
    };

    JavaScript
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups