Need Urgent help in Node Js

Discussion in 'Masters Program - Customers only' started by Ruchika_12, Dec 16, 2017.

  1. Ruchika_12

    Ruchika_12 Customer
    Customer

    Joined:
    Oct 4, 2017
    Messages:
    22
    Likes Received:
    3
    Hii..Can anyone help me I am not able to create a server on node js I am attaching the code and related output below.Please can anyone assist me in that. Screen Shot 2017-12-16 at 6.19.01 PM.png Screen Shot 2017-12-16 at 6.19.38 PM.png Screen Shot 2017-12-16 at 6.23.43 PM.png
     
    #1
  2. Rakesh Deshpande

    Rakesh Deshpande Moderator
    Simplilearn Support

    Joined:
    May 3, 2016
    Messages:
    769
    Likes Received:
    62
    Hello Ruchika,

    Suggestions: you can use IIFEs ( Immediately invoked Function expressions ) where you can just append the javascript fuction with .listen(3000, ' IP ');

    the code should be :

    var http =require("http");

    http.createServer(function(request, response){

    // Send the HTTP header // HTTP Status: 200 : OK// Content Type: text/plain
    response.writeHead(200,{'Content-Type':'text/plain'});

    // Send the response body as "Hello World"
    response.end('Hello World\n');}).listen(8081);

    // Console will print the message
    console.log('Server running at http://127.0.0.1:8081/');

    NOTE: IP should extend with :localport number. If your local port number is 8081 then you can go ahead appending like 127.0.0.1:8081 .

    It should work fine..
     
    #2
    Ruchika_12 likes this.
  3. Shubham kishorpuria

    Customer

    Joined:
    Nov 16, 2017
    Messages:
    6
    Likes Received:
    1
    hi .. I am using request module in node.js and check the status but it can show in console "undefined" then how to resolve this ???
     

    Attached Files:

    #3
  4. Rakesh Deshpande

    Rakesh Deshpande Moderator
    Simplilearn Support

    Joined:
    May 3, 2016
    Messages:
    769
    Likes Received:
    62
    Hello Shubham,

    I didn't catch you properly, what you're trying to do? are you saying that when you print on console, it says "undefined"?
     
    #4
  5. Shubham kishorpuria

    Customer

    Joined:
    Nov 16, 2017
    Messages:
    6
    Likes Received:
    1
    I used the request module in code and used callback function argument "status" it can print on console but it can show on console is undefined.
     
    #5
  6. Rakesh Deshpande

    Rakesh Deshpande Moderator
    Simplilearn Support

    Joined:
    May 3, 2016
    Messages:
    769
    Likes Received:
    62
    I would suggest, Check if the site is really returning a value for "status".

    add lines :

    if(status) { console.log(status); }

    and let me know. If this is not returning any response then try with other URL.
     
    #6

Share This Page