Getting started with Node.js
In this tutorial, We will create first Node.js application that simply return Hello, World! to the client.
In this tutorial, We will create first Node.js application that simply return Hello, World! to the client.
Create App in Node.js
Once you have installed Node, create a file named app.js, and paste the following code.
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World\n');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
Run Node.js App
Navigate to the folder which contain app.js file and run following command on terminal.
node app.js
Open your favourite browser and search http://127.0.0.1:3000Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Comments
Post a Comment