Creating Hello World Application In Node.js | CampCodes ...

Creating Hello World Application in Node.js

May 30, 2020
Node.js
hello world in node.js

Here, we will learn to create Node.js with simple hello world application.

Run or Execute this JavaScript File:

  1. Open Visual Studio Code IDE. If you are unfamiliar with this, you can go to this tutorial: Setup and Install Node.js
  2. Create a file named hello_world.js
  3. Write the code like as shown below.
    console.log('hello world');
  4. To execute to program open terminal.
  5. Type: “node (hello_world)” into the terminal.

Output:

hello world in node.js

You can also execute to run this Node.js Application:

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('Hello World!');
}).listen(8080);
  1. Start your internet browser, and type in the address: http://localhost:8080
  2. Now, your computer works as a server! If anyone tries to access your computer on port 8080, they will get a “Hello World!” message in return!

How to Download & Install Node.js - NPM on Windows

Check out this video tutorial below:

 

Leave a Reply

Your email address will not be published. Required fields are marked *