Home > Article > Web Front-end > Let’s talk about the installation and configuration files of Node.js
Node.js is an open source cross-platform JavaScript runtime environment that allows JavaScript to run on the server. Node.js uses an event-driven, non-blocking I/O model and can be used to build fast and scalable network applications. . This article will introduce the installation and configuration files of Node.js.
Node.js official website provides installation packages for Windows, Mac and Linux systems. Users can follow Select the corresponding installation package for your system to download. The URL is: https://nodejs.org.
NVM (Node Version Manager) is a tool for managing and switching multiple Node.js versions, which can help users use different versions in different environments more conveniently. Node.js. The use of NVM is also very simple. Just enter the following command in the terminal to install:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash
After the installation is complete, you can check the version of nvm through the following command:
nvm --version
In Windows systems, after installing Node.js, you need to add the path of Node.js to the environment variable PATH before you can use the Node.js command. In Windows 10, you can use the following methods to configure environment variables:
After installing Node.js, you need to make some configurations to better use Node.js.
npm (Node Package Manager) is the default package management tool for Node.js, which can be used to install and manage Node.js modules. The configuration file of npm is ~/.npmrc (Linux/Mac) or %userprofile%.npmrc (Windows). Users can configure npm according to their own needs.
Since the default npm mirror source may cause problems such as slow speed and download failure when used in China, you can modify the mirror source to the domestic Taobao source. or cnpm source. Enter the following command in the terminal to modify the mirror source:
npm config set registry https://registry.npm.taobao.org/
Some errors may occur when installing modules with npm. You can report the errors to the development through the following configuration Author:
npm set loglevel=http
In Windows systems, npm will install the globally installed Node.js module in the C drive by default, and the C drive usually It is a system disk, which may cause problems such as system lag, so you can modify the npm installation path to another drive letter. Enter the following command in the terminal to modify the installation path of npm:
npm config set prefix "D:\Program Files\nodejs\node_global" # 修改全局包安装路径 npm config set cache "D:\Program Files\nodejs\node_cache" # 修改缓存路径
The configuration file of Node.js is ~/.bashrc (Linux) or %userprofile %.bash_profile (Mac) or %userprofile%.bashrc (Windows), you can add custom Node.js environment variables to this file.
NODE_ENV is an important environment variable in Node.js, which can be used to distinguish the development environment from the production environment. In Linux and Mac systems, NODE_ENV can be set in the following ways:
export NODE_ENV=production
In Windows systems, NODE_ENV can be set by adding the following code in ~/.bashrc or %userprofile%.bash_profile:
set NODE_ENV=production
You can set aliases for commonly used commands in the terminal to make it more convenient for users to use. For example, you can set an alias for the node command:
In Linux and Mac systems:
alias n=node
In Windows systems:
doskey n=node
The above is the Node.js introduced in this article Installation and configuration files, I hope it will be helpful to everyone's learning.
The above is the detailed content of Let’s talk about the installation and configuration files of Node.js. For more information, please follow other related articles on the PHP Chinese website!