Here, we will learn to create Node.js with simple hello world application.
Run or Execute this JavaScript File:
- Open Visual Studio Code IDE. If you are unfamiliar with this, you can go to this tutorial: Setup and Install Node.js
- Create a file named hello_world.js
- Write the code like as shown below.
console.log('hello world');
- To execute to program open terminal.
- Type: “node (hello_world)” into the terminal.
Output:
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);
- Start your internet browser, and type in the address: http://localhost:8080
- 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!
Check out this video tutorial below: