Skip to content

Commit 6320af2

Browse files
committed
2022.08.07
1 parent 40cb4c6 commit 6320af2

3 files changed

Lines changed: 319 additions & 1 deletion

File tree

Cute-Summary/article/6 Interesting JavaScript Questions You Should Know.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ of course, if you want to return an `{}` object, you can just put `{}` it inside
124124

125125
```javascript
126126
let f2 = () => ({});
127-
f2(); // -> undefined
127+
f2(); // -> {}
128128
```
129129

130130
### 4. Can the function be executed using backquotes?
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
Article review: <[How to select the Node.js Version](https://medium.com/@Chris1993/how-to-select-the-node-js-version-3a6ae31be18c)>
2+
3+
When our local development environment needs to install Node.js 8.0.0 and Node.js 17.0.0 at the same time, how to do it?
4+
5+
Next, I will share 3 tools for managing the Node.js version of the local environment.
6+
7+
## 1. nvm
8+
9+
*Github stars: 60K+*
10+
11+
[nvm](https://github.com/nvm-sh/nvm) allows you to quickly install and use different versions of node via the command line.
12+
13+
![](https://images.pingan8787.com/images/20220807/image1.png)
14+
(Image from: [github](https://github.com/nvm-sh/nvm#additional-notes))
15+
16+
nvm can only be used in projects for macOS and Linux users. If you are Windows users, you can use [nvm-windows](https://github.com/coreybutler/nvm-windows), [nodist](https://github. com/marcelklehr/nodist) or [nvs](https://github.com/jasongin/nvs).
17+
18+
### Installation
19+
20+
macOS download method:
21+
22+
```bash
23+
# Method 1 Browser open the following link to download
24+
https://github.com/nvm-sh/nvm/blob/v0.39.1/install.sh
25+
# After the download is complete, install it through the command
26+
sh install.sh
27+
28+
# Method 2 ✅
29+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
30+
31+
# Method 3
32+
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
33+
````
34+
35+
If you encounter problems during the installation process, you can check the [nvm supplementary notes](https://github.com/nvm-sh/nvm#additional-notes).
36+
37+
### Common commands
38+
39+
```bash
40+
nvm ls # view version install all versions
41+
nvm ls-remote # View all remote Node.js versions
42+
nvm install 17.0.0 # Install the specified Node.js version
43+
nvm use 17.0.0 # use the specified Node.js version
44+
nvm alias default 17.0.0 # Set the default Node.js version
45+
nvm alias dev 17.0.0 # Set the alias of the specified version, for example, set the alias of version 17.0.0 to dev
46+
````
47+
48+
**Example**:
49+
```bash
50+
$ nvm use 16
51+
Now using node v16.9.1 (npm v7.21.1)
52+
$ node -v
53+
v16.9.1
54+
$ nvm use 14
55+
Now using node v14.18.0 (npm v6.14.15)
56+
$ node -v
57+
v14.18.0
58+
$ nvm install 12
59+
Now using node v12.22.6 (npm v6.14.5)
60+
$ node -v
61+
v12.22.6
62+
````
63+
Simple as that!
64+
65+
## 2. n
66+
67+
*Github stars: 16.7K+*
68+
69+
[n](https://github.com/tj/n) is an interactive Node.js version manager: no subshells, no profile setup, no convoluted API, just simple.
70+
71+
![](https://images.pingan8787.com/images/20220807/image3.gif)
72+
73+
`n` is supported on macOS, Linux, including with Windows Subsystem for Linux, and various other unix-like systems. It is written as a BASH script but does not require you to use BASH as your command shell.
74+
75+
### Installation
76+
77+
If you already have Node.js installed, an easy way to install `n` is using npm:
78+
79+
```bash
80+
npm install n -g
81+
````
82+
83+
[Third Party Installers](https://github.com/tj/n#third-party-installers)
84+
85+
### Common commands
86+
87+
```bash
88+
n # show all downloaded versions
89+
n 10.16.0 # Download the specified version
90+
n lts # View all LTS Node.js versions remotely
91+
n run 10.16.0 # run the specified Node.js version
92+
````
93+
94+
Use the `n -h` command to read help information, there are these main commands:
95+
96+
```bash
97+
n Display downloaded Node.js versions and install selection
98+
n latest Install the latest Node.js release (downloading if necessary)
99+
n lts Install the latest LTS Node.js release (downloading if necessary)
100+
n <version> Install Node.js <version> (downloading if necessary)
101+
n install <version> Install Node.js <version> (downloading if necessary)
102+
n run <version> [args ...] Execute downloaded Node.js <version> with [args ...]
103+
n which <version> Output path for downloaded node <version>
104+
n exec <vers> <cmd> [args...] Execute command with modified PATH, so downloaded node <version> and npm first
105+
n rm <version ...> Remove the given downloaded version(s)
106+
n prune Remove all downloaded versions except the installed version
107+
n --latest Output the latest Node.js version available
108+
n --lts Output the latest LTS Node.js version available
109+
n ls Output downloaded versions
110+
n ls-remote [version] Output matching versions available for download
111+
n uninstall Remove the installed Node.js
112+
````
113+
114+
## 3. fnm
115+
116+
*Github stars: 8.4K+*
117+
118+
[fnm](https://github.com/Schniz/fnm): 🚀 Fast and simple Node.js version manager, built in Rust
119+
120+
![](https://images.pingan8787.com/images/20220807/image4.png)
121+
(Image from: [freecodecamp](https://www.freecodecamp.org/news/fnm-fast-node-manager/))
122+
123+
**Features include**:
124+
125+
🌎 Cross-platform support (macOS, Windows, Linux)
126+
127+
✨ Single file, easy installation, instant startup
128+
129+
🚀 Built with speed in mind
130+
131+
📂 Works with .node-version and .nvmrc files
132+
133+
### Installation
134+
135+
macOS / Linux environment:
136+
137+
```bash
138+
# bash, zsh and fish shells
139+
curl -fsSL https://fnm.vercel.app/install | bash
140+
````
141+
142+
Windows environment:
143+
144+
```bash
145+
# Open the terminal in administrator mode. After installation, it can only be opened in administrator mode.
146+
147+
choco install fnm
148+
149+
# After the installation is complete, you need to manually set the environment variables
150+
````
151+
152+
Linux/macOS/Windows environments can also directly download binary files for installation, download address: [https://github.com/Schniz/fnm/releases](https://github.com/Schniz/fnm/releases)
153+
154+
### Common commands
155+
156+
```bash
157+
fnm -h # View help
158+
fnm install 17.0.0 # Install the specified Node.js version
159+
fnm use 17.0.0 # use the specified Node.js version
160+
fnm default 17.0.0 # Set the default Node.js version
161+
````
162+
163+
If you have a better tool, please leave a message to share.
164+
165+
If this article helps you, please like and support it.👍
166+
167+
✨follow me: https://dev.to/chris1993
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
在上一篇文章《[3 分钟掌握 Node.js 版本的区别](https://juejin.cn/post/7126183800874205220)》中介绍了 Node.js 版本分为 LTS 和 Current 系列,当我们需要在本地开发环境同时安装 LTS 版本和 Current 版本时,就需要对 Node.js 版本进行版本管理。
2+
3+
比如本地需要同时安装 Node.js 8.0.0 和 Node.js 17.0.0。
4+
5+
为了能够对 Node.js 版本进行版本管理,我整理了 3 款非常实用的 Node.js 版本管理工具,让大家能够自由的切换本地环境不同的 Node.js 版本。
6+
7+
## 1. nvm
8+
9+
*Github stars: 60K+*
10+
11+
[nvm](https://github.com/nvm-sh/nvm) 是一款 Node.js 版本管理工具,允许用户通过命令行快速安装、切换和管理不同的 Node.js 版本。
12+
13+
![](https://images.pingan8787.com/images/20220807/image1.png)
14+
(图片来自:[github](https://github.com/nvm-sh/nvm#additional-notes)
15+
16+
nvm 只适用于 macOS 和 Linux 用户的项目,如果是 Windows 用户,可以使用 [nvm-windows](https://github.com/coreybutler/nvm-windows)[nodist](https://github.com/marcelklehr/nodist)[nvs](https://github.com/jasongin/nvs) 替换。
17+
18+
### 安装方式
19+
20+
macOS 下载方式:
21+
22+
```bash
23+
# 方式1 浏览器打开下面链接下载
24+
https://github.com/nvm-sh/nvm/blob/v0.39.1/install.sh
25+
# 下载完成后,通过命令安装
26+
sh install.sh
27+
28+
# 方式2 推荐
29+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
30+
31+
# 方式3
32+
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
33+
```
34+
35+
安装过程中如果遇到一些奇怪的问题,可以查看下 [nvm 补充说明](https://github.com/nvm-sh/nvm#additional-notes)
36+
37+
### 常用命令
38+
39+
```bash
40+
nvm ls # 查看版本安装所有版本
41+
nvm ls-remote # 查看远程所有的 Node.js 版本
42+
nvm install 17.0.0 # 安装指定的 Node.js 版本
43+
nvm use 17.0.0 # 使用指定的 Node.js 版本
44+
nvm alias default 17.0.0 # 设置默认 Node.js 版本
45+
nvm alias dev 17.0.0 # 设置指定版本的别名,如将 17.0.0 版本别名设置为 dev
46+
```
47+
48+
![](https://images.pingan8787.com/images/20220807/image2.png)
49+
50+
## 2. n
51+
52+
*Github stars: 16.7K+*
53+
54+
[n](https://github.com/tj/n) 是一款交互式的 Node.js 版本管理工具,没有子脚本,没有配置文件,也没有复杂的 API,使用起来非常简单。
55+
56+
![](https://images.pingan8787.com/images/20220807/image3.gif)
57+
58+
n 只适用于 macOS 和 Linux ,不适用于 Windows。
59+
60+
### 安装方式
61+
62+
可以使用 npm 直接安装到全局:
63+
64+
```bash
65+
npm install n -g
66+
```
67+
68+
### 常用命令
69+
70+
```bash
71+
n # 显示所有已下载版本
72+
n 10.16.0 # 下载指定版本
73+
n lts # 查看远程所有 LTS Node.js 版本
74+
n run 10.16.0 # 运行指定的 Node.js 版本
75+
```
76+
77+
输入 `n -h`查看帮助信息,主要命令如下:
78+
79+
```bash
80+
n Display downloaded Node.js versions and install selection
81+
n latest Install the latest Node.js release (downloading if necessary)
82+
n lts Install the latest LTS Node.js release (downloading if necessary)
83+
n <version> Install Node.js <version> (downloading if necessary)
84+
n install <version> Install Node.js <version> (downloading if necessary)
85+
n run <version> [args ...] Execute downloaded Node.js <version> with [args ...]
86+
n which <version> Output path for downloaded node <version>
87+
n exec <vers> <cmd> [args...] Execute command with modified PATH, so downloaded node <version> and npm first
88+
n rm <version ...> Remove the given downloaded version(s)
89+
n prune Remove all downloaded versions except the installed version
90+
n --latest Output the latest Node.js version available
91+
n --lts Output the latest LTS Node.js version available
92+
n ls Output downloaded versions
93+
n ls-remote [version] Output matching versions available for download
94+
n uninstall Remove the installed Node.js
95+
```
96+
97+
## 3. fnm
98+
99+
*Github stars: 8.4K+*
100+
101+
[fnm ](https://github.com/Schniz/fnm)是一款快速简单 🚀 的 Node.js 版本管理器,使用 Rust 构建。
102+
103+
![](https://images.pingan8787.com/images/20220807/image4.png)
104+
(图片来自:[freecodecamp](https://www.freecodecamp.org/news/fnm-fast-node-manager/))
105+
106+
主要特点包括:
107+
108+
- 🌎 跨平台支持,包括:macOS、Windows、Linux;
109+
- ✨ 单一文件,轻松安装,即时启动 ;
110+
- 🚀 以速度为设计理念;
111+
- 📂 适用于 `.node-version``.nvmrc` 文件;
112+
113+
### 安装方式
114+
115+
macOS / Linux 环境:
116+
117+
```bash
118+
# bash, zsh and fish shells
119+
curl -fsSL https://fnm.vercel.app/install | bash
120+
```
121+
122+
Windows 环境:
123+
124+
```bash
125+
# 管理员模式打开终端,安装后只能使用管理员模式打开使用
126+
127+
choco install fnm
128+
129+
# 安装完成还需要手动设置环境变量
130+
```
131+
132+
Linux/macOS/Windows 环境也可以直接下载二进制文件安装,下载地址:[https://github.com/Schniz/fnm/releases](https://github.com/Schniz/fnm/releases)
133+
134+
### 常用命令
135+
136+
```bash
137+
fnm -h # 查看帮助
138+
fnm install 17.0.0 # 安装指定 Node.js 版本
139+
fnm use 17.0.0 # 使用指定 Node.js 版本
140+
fnm default 17.0.0 # 设置默认 Node.js 版本
141+
```
142+
143+
## 总结
144+
145+
本文为大家推荐了 3 款非常常用的 Node.js 版本管理工具,大家可以按照自己实际需求选择使用。
146+
147+
如果大家有更好的工具,欢迎留言分享。
148+
149+
如果本文给您带来帮助,还请点赞支持一下啦。
150+
151+
欢迎关注微信公众号“前端自习课”。

0 commit comments

Comments
 (0)