Hello Friends, In this tutorial we are going to learn about installation and configuration of node.js in our system.
This will be your first “Hello World” program using node.js.
How to install node.js on ubuntu
I have linux(ubuntu) machine so i ran this command to install node.js in my system
$ sudo apt-get update $ sudo apt-get install -y nodejs |
After installation check node.js installed successfully or not by this command
It’ll display currently installed node version.
If you have window’s machine then you can directly download node.js exe and run.
https://nodejs.org/download/
Now time to create your first hello world program.
create file name app.js in your helloworld directory.
app.js
// Load the http module to create an http server. var http = require('http'); // Configure our HTTP server to respond with Hello World to all requests. var server = http.createServer(function (request, response) { response.writeHead(200, {"Content-Type": "text/plain"}); response.end("Welcome in Hello World"); }); // Listen on port 5000 server.listen(5000); // Set confirmation message with hostname and port console.log("Server running at http://127.0.0.1:5000/"); |
And run below command on your terminal to execute your program and see output on browser and terminal.
Hope this tutorial will help you to create your first hello world program in nodejs. 🙂