> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/ask/flat/chapter-21-development-environments/di-21.7-jie-node-js-kai-fa-huan-jing.md).

# 21.7 Node.js Development Environment

Node.js depends on a specific version of **/lib/libcrypto.so**. Before installing on FreeBSD, the base system must be updated first.

## Updating the Base System

Node.js installed via pkg depends on a specific version of the **/lib/libcrypto.so.xxx** file. When using Node.js on FreeBSD, you need to pay attention to the FreeBSD system version, especially when pkg is configured to use the latest repository.

Before installing Node.js on FreeBSD, the base system should be updated first.

Installing npm or yarn will automatically install the corresponding version of Node.js; Bun uses its own runtime and does not depend on Node.js.

## Node.js Package Manager Comparison

| Evaluation Dimension  | npm                                       | Yarn                                     | Bun                                            |
| --------------------- | ----------------------------------------- | ---------------------------------------- | ---------------------------------------------- |
| Underlying language   | JavaScript                                | JavaScript                               | Zig                                            |
| Execution runtime     | Node.js                                   | Node.js                                  | Native Bun Runtime                             |
| Dependency resolution | Flat dependency tree + hoisting           | node\_modules / Plug'n'Play (PnP)        | High-concurrency install + flat node\_modules  |
| Disk storage strategy | Physical `node_modules`                   | `node_modules` or PnP virtual resolution | Global cache + hard link/clone optimization    |
| Lock file             | `package-lock.json`                       | `yarn.lock`                              | `bun.lock`                                     |
| TypeScript support    | Depends on `tsc` / `tsx` / `esbuild` etc. | Same as npm                              | Native `.ts` execution                         |
| Compatibility         | Node.js official standard                 | High compatibility                       | Node API compatibility still needs improvement |

Bun is a JavaScript runtime, not just a Node.js package manager.

## Bun

Install using pkg:

```sh
pkg install bun
```

Or install using Ports:

```sh
# cd /usr/ports/lang/bun/
# make install clean
```

## Yarn

Install using pkg:

```sh
# pkg install yarn
```

Or install using Ports:

```sh
# cd /usr/ports/www/yarn/
# make install clean
```

## NPM

Install using pkg:

```sh
# pkg install npm
```

Or install using Ports:

```sh
# cd /usr/ports/www/npm/
# make install clean
```

### Switching NPM Registry on FreeBSD

Set npm to use a domestic mirror to speed up downloads:

```sh
# npm config set registry https://registry.npmmirror.com
```

This site is the former Taobao mirror. For details, see <https://npmmirror.com>, which provides NPM Chinese mirror acceleration services.

## Troubleshooting and Unfinished Business

### ld-elf.so.1 Error

If you skip updating the FreeBSD base system and install software directly, you may encounter the following error:

```sh
$ node              # Start the Node.js interactive command line
ld-elf.so.1: /lib/libcrypto.so.111: version OPENSSL_1_1_1e required by /usr/local/bin/node not found
```

> **Note**
>
> The `libcrypto.so.111` in the above error message corresponds to OpenSSL 1.1.1 (FreeBSD 13 and earlier). In FreeBSD 14, the base system's OpenSSL has been upgraded to 3.x, with the corresponding library file being `libcrypto.so.30`; in FreeBSD 15 and later, the corresponding library file is `libcrypto.so.35`. The error message will differ, but the root cause is the same: the base system needs to be updated first.

Ports compile based on the current system's library version, so installing via Ports compilation will not produce the above issue.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://book.bsdcn.org/ask/flat/chapter-21-development-environments/di-21.7-jie-node-js-kai-fa-huan-jing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
