Home > Article > Web Front-end > Reviewing Node JS
This weekend I decided to review a little about JavaScript and Node. That's because I bumped into the definition while testing a project that appeared in my GitHub feed.
I also plan to study some topics like the event loop and promises in more depth, so a review would be great.
Here are my notes.
It is an environment (runtime) that allows JavaScript to be executed on the server side. With it, you can create applications that run outside the browser (back end, mobile, desktop applications...).
Just to remind you, JavaScript is an interpreted and multi-paradigm programming language created to add interactivity to web pages, that is, it was developed with the intention of being used in the browser.
Nowadays there are other JavaScript execution environments such as Deno or Bun, but Node was the pioneer, launched in 2009.
The possibility of developing both the front end and the back end of an application using just one programming language is fantastic. This ability is one of the great advantages of JavaScript, although some professionals question its use on the server side.
Thinking about Java's motto "Write once, run anywhere", we have ours: learn once, create everything.
Node is based on Google Chrome's V8 engine, which reads and executes JavaScript code in the browser. An important feature is that a JavaScript engine is independent of the browser in which it runs, which allowed the creation of Node and other environments.
There are other JavaScript engines:
JavaScript is considered an interpreted language but the engines have a just-in-time (JIT) compilation step, making it an interpreted and compiled language.
It is important to note that Node does not have access to the DOM, window, etc. manipulation APIs. Instead of these, it has its standard library that allows you to access the file system, listen to HTTP requests, generate UUIDs, emit events and many other things.
// ❌ const element = document.getElementById('js-in-server') console.log(element.textContent) // ✅ import fs from 'fs' fs.readFile('js-is-really-cool.md', 'utf-8', (err, content) => { console.log(content) })
Node comes equipped with the NPM package manager (Node Package Manager) which is used to organize, install and resolve project dependencies. NPM is also the default package registrar, it is where libraries and frameworks are registered for later use.
Just to clarify, there is the NPM package management tool and the registrar for these packages, which is also called NPM. More about here.
Alternatives to the tool are yarn and pnpm. The Bun environment also has a package manager that is compatible with Node and is intended to be the fastest replacement among the options I mentioned before.
Speaking of the registrar, recently a kind of modern alternative has emerged that claims to be made for Typescript and ESM, JSR.
Some really cool "new" features that I remember were added to Node:
That's it for now, I intend to update this review to cover what event loop is and its importance.
A fun fact is that I developed my first HTTP server using Node and it was with it that I discovered I liked back end.
Thanks for reading!
The above is the detailed content of Reviewing Node JS. For more information, please follow other related articles on the PHP Chinese website!