I am very new to node.js and I am wondering the best way to test the following type of code in general. Right now I am doing it all as one file in a netbeans node.js project. I am getting no output, the output should be "HELLO SERVER".
it usually compiles with no errors, but there is no output, other times it says
"throw er; // Unhandled 'error' event Error: listen EADDRINUSE :::8000"
I already know what this rejection means and I think it is just doing that when I click run twice because then the port is occupied by the first run.
I have already tried on multiple ports, it works but with no output...
Should I be testing this some other way? Why is there no output? Output should be "HELLO SERVER" Thank you.
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
request.on("data", function (chunk) {
response.write(chunk.toString().toUpperCase());
});
request.on("end", function () {
response.end();
});
}).listen(8000);
var http = require("http");
var request = http.request({
hostname: "localhost",
port: 8000,
method: "POST"
}, function (response) {
response.on("data", function (chunk) {
process.stdout.write(chunk.toString());
});
});
request.end("Hello Server");