Xintao
Xintao
发布于 2024-01-07 / 12 阅读
0

好用的NPM管理器

好用的NPM管理器

这两天突然想要写一个简单的小项目。项目设计的时候呢想要把前后端分离,后端也就是简单逻辑,就是用Flask框架完全够用了,也不需要考虑多线程高并发什么的,问题就不大,直接用Python就可以做一切的配置工作。前端一般要用Node.js,但是环境配置工作是我很久以前做的,今天再次用的时候配置环境都忘了当时是怎么配置的了,目录也忘了在哪里,干脆就重新配置。

重新配置的话刚好看到一个b站up主用的nvm,就好奇的搜了一下,才发现这个好用的Node版本管理器。这里直接丢出来Github项目地址【跳转】

部署过程

我的电脑是Windows系统,就使用了这个nvm专门的Windows版本: NVM for Windows,下面的内容也就是基于这个版本进行搭建分享的。

遇到的问题

我的主机配置原本有node环境,就想着直接装,发现不行,有冲突,试了好几次也不成功。仔细查看项目README文件才知道,原有版本与nvm存在冲突或者说不兼容,而且官方也是建议卸载主机上原有的环境。那我就老老实实卸载,然后装上NVM。装上以后我就打开了新世界NVM真的好用。他的安装过程也很简单,下面让我们开始吧。

安装过程

下载

首先直接去项目地址下载,下载地址: 【跳转】

https://github.com/coreybutler/nvm-windows/releases 

安装

下载完成以后直接双击安装包进行安装。根据配置进行设置,然后完成。

  • 这里要注意的是有两个目录
    • 安装过程中第一个目录是指nvm安装目录
    • 遇到的第二个目录配置是指的在系统环境变量中要配置的node环境目录。它会在该位置生成一个链接(快捷方式)连接到当前使用版本的Node的安装目录。这个目录一般默认在你第1个设置目录的子目录中。

使用

安装完成后你就可以使用下面的命令直接安装你需要的版本,例如安装 18.19.0

nvm install 18.19.0

当然还有许多其他命令,可以参考官方文档或者我下面截取自官方的文档。官方文档的内容:

使用管理员Shell运行nvm-windows,使用 nvm-windows 时,需要以管理员身份启动 powershell 或命令提示符。

Windows 版 NVM 是一款命令行工具。只需在控制台输入 nvm 即可获得帮助。基本命令如下:

  • nvm arch [32|64]: Show if node is running in 32 or 64 bit mode. Specify 32 or 64 to override the default architecture.

  • nvm check: Check the NVM4W process for known problems.

  • nvm current: Display active version.

  • nvm install <version> [arch]: The version can be a specific version, "latest" for the latest current version, or "lts" for the most recent LTS version. Optionally specify whether to install the 32 or 64 bit version (defaults to system arch). Set [arch] to "all" to install 32 AND 64 bit versions. Add --insecure to the end of this command to bypass SSL validation of the remote download server.

  • nvm list [available]: List the node.js installations. Type available at the end to show a list of versions available for download.

  • nvm on: Enable node.js version management.

  • nvm off: Disable node.js version management (does not uninstall anything).

  • nvm proxy [url]: Set a proxy to use for downloads. Leave [url] blank to see the current proxy. Set [url] to "none" to remove the proxy.

  • nvm uninstall <version>: Uninstall a specific version.

  • nvm use <version> [arch]: Switch to use the specified version. Optionally use latest, lts, or newest. newest is the latest installed version. Optionally specify 32/64bit architecture. nvm use <arch> will continue using the selected version, but switch to 32/64 bit mode. For information about using use in a specific directory (or using .nvmrc), please refer to issue #16.

  • nvm root <path>: Set the directory where nvm should store different versions of node.js. If <path> is not set, the current root will be displayed.

  • nvm version: Displays the current running version of NVM for Windows.

  • nvm node_mirror <node_mirror_url>: Set the node mirror.People in China can use https://npmmirror.com/mirrors/node/

  • nvm npm_mirror <npm_mirror_url>: Set the npm mirror.People in China can use https://npmmirror.com/mirrors/npm/

总结

nvm安装完成后完成后就用NVm install就可以安装,也可以选择你要使用的no的版本。这里我还要再夸一句,它是真的好用,免去了我以前配置环境的过程包括但是不限于全局环境和缓存目录。并且安装位置我可以自定义,以免我找不到。而且还可以自动配置环境变量。

NVMYYDS!今天的分享就到这里了,感谢你们的收看。