Home > Web Front-end > JS Tutorial > body text

Reviewing Node JS

Mary-Kate Olsen
Release: 2024-11-01 14:33:02
Original
211 people have browsed it

Revisando 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.

What is Node

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:

  • Firefox uses SpiderMonkey
  • Safari uses JavaScriptCore
  • Edge used the Chakra and currently uses the V8

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)
})
Copy after login

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:

  • Loading environment variables (.env)
  • Test runner, stably introduced in version 20.x
  • Typescript execution, still experimental

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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template