So I am very to node.js. I have netbeans and also a few front-end environments like atom.
The first exercises consist of code that creates a server, and then other code that sends a request to that server. I am just confused about how to test both ends of the code in this situation. Should I just enter all the code (see below) into one js document in netbeans and run it? (already have tried this… and didn’t see any useful output but also no errors) or do I have to put the request code in a browser side environment like atom and the server in a node.js/netbeans project?
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 World");