Programming

Node.js

What is Node.js?

Node.js runs JavaScript on the V8 engine. Files, the network, and processes open from here. Packages come with npm. JavaScript in the browser changes the page. Node stays in the terminal and on the server.

What is Node.js used for?

Node.js is for an API, a build tool, and an automation script.

  • An HTTP server that returns JSON
  • A frontend build
  • An npm script
  • A Capacitor or CLI tool

What can you do with Node.js?

With Node you write a small API, a script that reads a file, and a command that builds a browser bundle. It is not the first choice for a long CPU calculation, because it is built on one main thread. It is strong for network work that waits.

Is Node.js hard to learn?

If you know JavaScript, the entrance is short. The difficulty is async code, package versions, and the flow of promises instead of callbacks. node and npm are different commands. One is the runtime. The other is the package tool.

Advantages and limits

Advantage: the same language in the browser and on the server, and a huge number of packages. Limit: it is weak at heavy calculation, and an old package can bring a security hole. The Node version should be written in the project’s engines field.

Basic ideas

A module opens with require or import. The process object shows environment variables. npm install puts a package into node_modules.

  • An LTS release is chosen for a server
  • package.json keeps the name and the scripts
  • npx can run a command without a global install
  • Node does not give a browser object such as window

A short example

This command writes one line to the terminal if Node is installed.

node -e "console.log('Hello')"

Common questions

  • Is Node.js a language? No. It is the runtime that runs JavaScript.
  • Do Node and the browser always run the same code? The network and file side differ. The shared language is the same.
  • Is npm Node itself? No. It is the package tool that comes with Node.