NodeJS: A Powerful Tool for Web Development
Tags: node, javascript, webdev
Published: 2021-11-14 00:32:16

JavaScript is a popular front-end language for making dynamic web pages in web browsers. But using JavaScript only in the browser can be limiting in web development. That’s why NodeJS is helpful.
<br />

## What is NodeJS?

> **Node.js** : A JavaScript runtime environment built outside the web browser.

To create a complete web service, you need both front-end and back-end development. This means making sure the web browser and the web server talk to each other smoothly. But for front-end developers, learning a new language for the server side can be hard. NodeJS, with its built-in HTTP server library, makes it possible to use JavaScript outside the browser. With NodeJS, you can create web services using only JavaScript.

![image](https://images.velog.io/images/joyact/post/5fb83e06-f57e-4bdd-8542-4fc7b843c8fb/image.png)

_\*\* NodeJS is good for apps that need real-time data processing and frequent I/O operations, like Single Page Applications (SPA). But it’s not recommended for CPU-intensive applications._

---

## ✔ npm

> npm : Node Package Manager(Modules)

`npm` is a package management tool that comes with NodeJS. These packages, also called modules, help you install various libraries needed for development, like webpack, Create React App (CRA), and react.

ex) `npm install webpack`

You can use the `npm init` command to create an initial `package.json` file and set up your project. Packages downloaded with npm are recorded in `package.json`.
<br />

### Disadvantage

- It takes up a lot of space because it installs packages directly on the local computer.
- When a new version of a package comes out, you have to update it manually.

---

## ✔ npx

> npx : Node Package Runner

`npx` is a package management tool introduced with npm version 5.2.0 and later. If you have downloaded npm version 5.2.0 or higher, npx is automatically installed and helps to use npm more conveniently.

ex) `npx install webpack`
<br />

### Advantages

- Packages are not stored directly on the computer; they are installed temporarily (no storage space is used).
- Always use the latest updated packages.

### How npx Works

1. By default, it checks if the package to be executed is in an executable path (e.g., checks if the package is installed in the project).
2. If it exists, it executes it.
3. If not, npx installs and executes the latest version of the package.

<br />

---

## ✔ Yarn

Yarn is a package manager similar to npm. The main difference is that it is not installed automatically with Node.js but requires a separate command for installation. When using Yarn, downloaded packages are recorded in a file called yarn.lock, ensuring that the same packages are installed on all devices.

- Installation of Yarn: `npm install -g yarn`

```bash
# Using npm
npm install <package>
npm uninstall <package>

# Using Yarn
yarn add <package>
yarn remove <package>
```

### Advantages

- Speed and reliability are similar to npm, but Yarn emphasizes better security and dependency management.
- Ensures consistent versions across all environments, reducing version conflicts and bugs caused by them.