Node.js can be used to build various types of applications such as command-line applications, web applications, real-time chat applications, REST API servers, etc. However, Node.js is mainly used for building network programs like web servers, similar to PHP, Java, or ASP.NET. In this article, Mytour will share useful information about Node.js and the Node.js Download link, inviting readers to follow along.
1. What is Node.js?
Node.js is an open-source cross-platform runtime environment for JavaScript, used to execute client-side web applications outside the client's browser. Node.js was written and introduced by Ryan Dahl in 2009 and is notable for the following features:
- Node.js is an open-source server-side framework.
- Node.js is free.
- Node.js runs on various platforms (including Windows, Linux, Unix, Mac OS X, …).
- Node.js utilizes JavaScript on the server. Download Java here
2. What are Node.js files?
- Node.js files contain tasks that will be executed on specific events.
- A typical event example is when someone tries to access a port on the server.
3. How Node.js Works
Node.js is a server-side development platform based on JavaScript. When a network request comes from a client, Node.js operates on the following principles:
- Node.js creates an event loop to track incoming and outgoing network requests.
Node.js handles incoming and outgoing network requests using callback functions, Promises, async/await to ensure asynchronous behavior and optimize application performance. Network requests are processed independently, avoiding blocking during request processing. Node.js also has the ability to work with various modules and libraries to support web application development.
4. Installing Node.js on Windows
Firstly, you need to download Node.js - Software for Managing and Organizing Network Applications. Get Node.js Download for free here:
Follow the steps below to install Node.js on your Windows computer:
Step 1: Click Install to run the .msi installer.
Step 2: Run the installer and follow the instructions to install NPM (node package manager) and Node.js.
Step 3: Restart your computer for everything to work on the command line interface (CLI).
Installing Node.js on Windows
The steps to install Node.js on Windows are quite simple. Just visit the Node.js homepage to download the installation package and run it.
Download node.msi installer for Windows
Visit the Node.js homepage to download the Windows .msi installation file. That's all you need to set everything up.
Running the node.msi installer
Run the Node .msi file from any location on your computer. The installation window will appear on the screen. All you need to do is click Agree and then click OK. If the Node.js installation process fails, you can rerun the file and select Repair to fix the issue.
Restart your computer
This is a step that many users often forget. After installing the .msi file, remember to restart your computer. Otherwise, your computer will prevent you from using Node in Command Prompt.
Testing Node.js on Windows
Although Node.js is installed, it doesn't mean it's working correctly. The next step below will guide you on how to create a test file to run Node.js.
Create a test file
To ensure Node.js works properly on Windows, try creating a simple Hello World script file using the code snippet above. Name the file test.js and store it in a safe location, such as C:\node\test.js for easier access via Windows Command Prompt. If saving the file elsewhere, remember to update the path.
Running Windows Command Prompt
test.js: Code snippet from http://nodejs.org home page.
1
2
3
4
5
6
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
Initiate Command Prompt and navigate to the directory of test.js (Refer to how to run Command Prompt here). Run the command node test.js to activate the file on Windows and display a notification.
Verify Node.js Installation on Windows
If you pay attention, you'll notice that when running node test.js, a notification similar to the server running at http://127.0.0.1:1337/ will appear on the screen. To verify if Node is functioning correctly when exiting Command Prompt running in the background, simply copy and paste http://127.0.0.1:1337 into the browser's address bar. The screen will display a message as shown in the illustration below.
Hopefully after this article, you'll grasp what Node.js is, know the link for Node.js Download as well as how to install Node.js on Windows. If you have any doubts or questions that need clarification, feel free to leave your comments in the comment section below the article!
