Skip to content
Shop

CommunityJoin Our DiscordDonate

Sponsored Ads

Sponsored Ads

Node

You probably know JavaScript – the language that powers interactive elements on websites. But what if you could use JavaScript for more than just the front-end (what you see in your browser)? That's where Node.js comes in!

What is Node? ​

Node.js isn't a programming language itself; it's a runtime environment. Think of it as a platform that allows you to execute JavaScript code outside of a web browser. It's built on Chrome's V8 JavaScript engine (the same engine that powers the Chrome browser). Essentially, it lets you use JavaScript to build server-side applications, command-line tools, desktop apps, and more.

Why Use Node? ​

Node.js has become incredibly popular, and for good reason. Here's a breakdown of the advantages:

  • JavaScript Everywhere: Being able to use one language (JavaScript) for both your front-end and back-end development significantly streamlines your workflow and reduces the learning curve.
  • Non-Blocking, Event-Driven Architecture: Node.js excels at handling many requests simultaneously without slowing down. This is crucial for applications that need to be highly responsive, like real-time chat apps or online games. It uses a "non-blocking" approach, meaning it doesn't wait for one task to finish before starting another.
  • Large and Active Community: A massive community means plenty of libraries, frameworks, and support resources are readily available. You can find help easily and leverage existing solutions.
  • NPM (Node Package Manager): NPM is the world’s largest software registry. It's a huge repository of reusable code modules (packages) that you can easily integrate into your projects.
  • Fast Performance: Utilizing the V8 engine, Node.js is generally very performant.
  • Scalability: Node.js applications are highly scalable, meaning they can handle increased traffic and load as your application grows.

Node Basics ​

Let's touch on a few fundamental concepts:

  • Modules: In Node.js, code is organized into reusable modules. These are self-contained units of functionality. You can import and use modules created by others or create your own.
  • require(): This is the keyword used to import modules. For example: const fs = require('fs'); (This imports the file system module).
  • npm (Node Package Manager): Used to install, manage, and share reusable code packages. You use commands like npm install <package-name> in your terminal.
  • Event Loop: This is the core mechanism that allows Node.js to handle asynchronous operations efficiently. It continuously monitors for events and executes associated callbacks.
  • Asynchronous Programming: A key concept in Node.js. It allows you to perform operations (like reading files or making network requests) without blocking the main thread, keeping your application responsive.
  • CommonJS: The original module system used by Node.js.

Getting Started ​

  1. Install Node.js: Download the installer from https://nodejs.org/.
  2. Open a terminal/command prompt: Navigate to a directory where you want to create your project.
  3. Create a package.json: Run npm init -y to quickly create a default package.json file.
  4. Write some JavaScript! Create a file named app.js (or whatever you prefer) and start writing your Node.js code.
  5. Run your code: Execute your code using the command node app.js.

Conclusion ​

Node.js has revolutionized web development and beyond. Its ability to run JavaScript on the server-side, along with its performance and scalability, makes it a powerful tool for building a wide range of applications. This article is just a starting point – there's a lot more to explore!


Keywords (for SEO): Node.js, JavaScript, server-side development, runtime environment, NPM, Node Package Manager, backend, asynchronous programming, event loop, Node.js tutorial, what is Node.js, Node.js basics.

NVM ​

To not have to run nvm use 22.13 with every new shell, add a file named .nvmrc to your project directory with the Node version:

bash
echo "22.13" > .nvmrc
nvm use

To make this automatic in every new shell:

🟢 For zsh (~/.zshrc) or bash (~/.bashrc or ~/.bash_profile), add:

bash
autoload -U add-zsh-hook

load-nvmrc() {
  local node_version="$(nvm version)"
  local nvmrc_path="$(nvm_find_nvmrc)"

  if [ -n "$nvmrc_path" ]; then
    local nvmrc_node_version=$(cat "$nvmrc_path")

    if [ "$nvmrc_node_version" != "$node_version" ]; then
      nvm use "$nvmrc_node_version"
    fi
  elif [ "$node_version" != "$(nvm version default)" ]; then
    nvm use default
  fi
}

add-zsh-hook chpwd load-nvmrc
load-nvmrc

For bash, the same logic can be written as a function in your ~/.bashrc.

If you want Node 22.13 to always be used in every shell session:

bash
nvm alias default 22.13

Now, every time you open a terminal, nvm will use Node 22.13 by default.

Resources ​