1

HI friends ... this might be a silly question but its hard for a beginner like me . I am trying to lean about webservices I have created a sample program in express that outputs a JSON

var http=require('http');
var express=require('express');


var app=express();


app.configure(function(){
    app.set('port',process.env.PORT || 5000);
    app.use(express.bodyParser());
});


app.get("/",function(req,res){

    res.json({Message:"HELLO_WORLD"});
});



http.createServer(app).listen(app.get('port'),function(){
    console.log("Server is running at port:" + app.get('port'));
});
  • I am able to execute this on my aws server when i run on it
  • how to access it from another desktop(ex:my home-PC)

when i give localhost:5000 it dosen't work. According to my knowledge the solution is WEBSERVICES .


how to create it .... what additional lines of code i need to add for this existing code. or if i need to create any other configuration file .... how to do it? . Thanks in advance

3 Answers 3

1

What is your error message, is it EADDINUSE? it's mean another version of your code still running and your port now in use, or some other application is using the port 5000. You should turn off your code or change the port

Sign up to request clarification or add additional context in comments.

3 Comments

Btw, you can check your local ip address, so other computer can access your service via that ip: your_ip:your_port
Hey thanks ... error cleared ..... what url should i need to give from local PC ? .... is it like myamazonserverip:5000
Oh!I guess you are running it on server right? If you run your service on a server, just use its ip, i'm not sure about port because your application will first read the enviroment parameter for port, the log message will tell you which port will be used, it usually port 80, you can try it first. If you run it on your pc, so use your local ip.
0

Just use app.listen not http.createServer

var app = express();

app.get('/', function(req, res) {
  res.send(200);
});

app.listen(3000);

2 Comments

Hey thanks for the i/p .... but i get an error when i use the above code as :: events.js:72 throw er; // Unhandled 'error' event ^ Error: listen EADDRINUSE at errnoException (net.js:884:11)
Adding to above comment .... without creating server how r u able to listen with above code snippet ...
0

Your code works just fine. Make sure you have express installed in the node_modules directory on the pc from which you are trying to execute the code.

1 Comment

HI Akshant ..... I have express module installed ... im running it on AWS(amazon server) ...... then i am trying to call it from my desktop PC with url in my browser .... here its not working

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.