1

iam new to node.js am trying to creating a http server and spawn a child process.

see the code

var server = http.createServer(function(req, res) {
res.writeHead(200);
  switch(req.url) {

        case '/vm/start':
            req.on('data', function(data) {             
            console.log("hello");
                console.log(data.toString());
                exec('CALin.exe', function(err, data) {     
                    console.log(err)
                    console.log(data.toString());


});
                    res.end('');
                });
            });

            break;
    }
});

server.listen(9090);
console.log("Server running on the port 9090");

while i trying to run the above code using this url http://172.16.2.51:9090/vm/start am getting nothing.and browser showing connection reset problem I dont know why this is happening

node server.js

Server running on the port 9090
5
  • can you try localhost:9090/vm/start Commented Oct 31, 2013 at 8:45
  • possible duplicate of client server communication using node.js Commented Oct 31, 2013 at 8:49
  • Remove the exec call and see if that works. For me it doesn't reset connection without it. Commented Oct 31, 2013 at 9:02
  • i need that exec call Commented Oct 31, 2013 at 9:07
  • shouldn't the res.end(''); be in the exec callback ? Commented Oct 31, 2013 at 10:59

2 Answers 2

1

There is no data being sent in the request so the data event does not get triggered and therefore res.end never gets called and the request times out. Add a listener for the requests end event and then call response.end.

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

Comments

0

Write your code in a js file and run it

var http = require("http");
var server = http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<!DOCTYPE "html">");
response.write("<html>");
response.write("<head>");
response.write("<title>Hello World Page</title>");
response.write("</head>");
response.write("<body>");
response.write("Hello World!");
response.write("</body>");
response.write("</html>");
response.end();
});

server.listen(9090);
console.log("Server is listening");

Run this code as

 node web_server.js

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.