How to Upload Node.js File and Run the Node.js?
To ensure the functionality of the Node.js application through browser, you can make use of the below given sample script.
http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('It is functioning!');
}).listen(2000);
console.log('Server running at port 2000');
Create a .js file (Example: demo.js) with the above given sample script. The script tells the engine to listen on port 2000 and as result it will display a sample message It is functioning! .
Ensure that the port 2000 is allowed inside the server's firewall.
You can run the demo.js script created in the below given format.
node demo.js
You can access the test script using your browser:
http://localhost:2000
How this faq is helpful: