In this article, you will learn about Node.js. You will learn the following:
- What is Node.js?
- How the Node.js environment differs from the browser.
- Why you should learn Node.js.
- How to get started with Node.js.
- Resources to help you learn Node.js.
What is Node.js?
This sounds like a cool, straightforward answer. But for a beginner, this definition might raise further questions. So let's break it down and understand what it means.
Node.js is open-source: This means that the source code for Node.js is publicly available. And it's maintained by contributors from all over the world. The Node.js contribution guide shows you how to contribute.
Node.js is cross-platform: Node.js is not dependent on any operating system software. It can work on Linux, macOS, or Windows.
Differences Between the Browser and Node.js Runtime Environments
Access to the DOM APIs
With the browser runtime, you can access the Document Object Model (DOM). And you can perform all the DOM operations. But Node.js does not have access to the DOM.
Node.js exposes almost all the system resources to your programs. This means you can interact with the operating system, access the file systems, and read and write to the files. But, you do not have access to operating systems and file systems from the browser.
Window vs Global object
window object. In Node.js, the global object goes by the name
window object contains methods and properties available only in the browser environment.
Control over runtime versions
Contrast this to the browser runtime environment. As a developer, you have no control over the version of browsers your clients use to access your app.
Loading modules (
Node.js offers out-of-the-box support for CommonJS and ES modules. You can load modules using the
require keyword (CommonJS syntax) and the
import keyword (ES syntax).
Some modern browsers support ES modules. This means you can use
import ES modules. But you will still need to create bundles to cater to older browsers that do not support ES modules.
How to Get Started with Node.js
Let's see how you can create your first Node.js application. This section will show you how to run Node.js scripts from the command line.
How to download and install Node.js
First, you need to download and install Node.js. There are different ways you can do that. If you are a beginner, I would suggest that you download Node.js from the official website.
Official packages are available on the website for all major platforms (Windows, macOS, and Linux). Download and install the appropriate package for your system.
How to check the Node.js version
To check the Node.js version, run the command
node --version in your terminal.
If the installation was successful, you will see the version of Node.js you installed. You should get a response like the screenshot below.
How to run Node.js from the command line
Let's build a simple
Hello World app.
Create a new project folder. You can call it
my-project. Open the project in your code editor. Inside the folder, create an
Add the following code to
You can run the script in the command line by running the command
node <fileName>. In this case, the file name is
Run the following command in your terminal to execute the
Hello world. program:
You should see the string "Hello world." logged in your terminal like so.
Congratulations! You just ran your first Node.js application.
Should You Learn Node.js?
Here are some reasons why you should consider learning Node.js
Node has a vibrant community.
As I mentioned earlier in the article, Node.js is open-sourced. It is actively maintained by developers from all over the world.
There is a vibrant community surrounding Node.js. You can find excellent tutorials and solutions to problems when you get stuck.
Node is built on top of Google Chrome's V8 engine.
Demand in the market
Many big names like Netflix, Uber, Paypal, and LinkedIn, and others use Node.js. Apart from the big names, many startups also use Node.js in developing their applications.
Learning to work with Node.js will make you a desirable candidate in the job market.
The NPM library
The NPM library is one of the excellent resources that comes with Node.js.
The library contains a registry of over a million packages. A package is a reusable piece of code.
You can create a package for a recurring task or problem and share the code with others via the registry.
You can also download packages that others have shared. For many tasks that developers perform regularly, there are packages available for that.
Resources to Learn Node
If you are curious about learning how to build Node.js applications, I recommend the following resources.
- 8-Hour Node.js and Express.js Course on freeCodeCamp YouTube Channel.
- The freeCodeCamp Backend Development and APIs curriculum
- Nodejs.dev Documentation
Also, below is a link to a video of Ryan Dahl when he first presented Node.js.
A single blog post like this is not enough to learn all there is to know about Node.js. The purpose of this article was to give you an overview of what Node.js is.
If you were not sure what Node.js is, I hope this article addressed your concerns and cleared your confusion.
Thanks for reading. And happy coding!