Node.js is a platform that uses JavaScript to build fast and scalable server applications. N ode.js is a runtime library, and npm is the package manager of N ode.js modules. In order to let novices build the basic environment needed for development as soon as possible, this doc is specially created. This article mainly focuses on the environment configuration under the Ubuntu Linux.
Nvm is a node.js version management tool. You can install and switch between different versions of node.js. It is recommended to use nvm to download and install node.js.
Detailed doc: https://github.com/nvm-sh/nvm
Please refer to the official doc for specific usage details.
1.Open the terminal and run either of the following two lines of commands.
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh
2.Configuration environment variables.
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
3.Verify whether the installation is successful
Execute nvm -v , if the output version number indicates that the installation was successful.
Or command -v nvm , if the output nvm means the installation was successful.
1.Enter nvm insatll --lts to install the latest LTS version of node.
2.enter nvm use xxxxxxxx to switch to any version.
NPM is a package management tool installed with Node.JS. It can solve many problems in NodeJS code deployment. The common usage scenarios are as follows:
Since the new version of node.js has been integrated with npm , npm has also been installed before. You can also enter the command npm -v to test whether the installation is successful. If the corresponding version number appears, the installation is successful.
Visual Studio Code ( VS Code for short) is a free cross-platform source code editor developed by Microsoft. The software supports syntax highlighting, code auto-completion (also known as IntelliSense), code refactoring functions, and has built-in command line tools and Git version control system. It is recommended to use VS Code for software development first.
1.Download
Official download link: https://code.visualstudio.com/download
Select the version of .deb to download:
2.Installation
Open end point in the directory where the installation package is located and enter sudo dpkg -i xxxx.deb
$ sudo dpkg -i code_1.66.0-1648620611_amd64.deb
3.Search
Then you can see the VSCode icon on the Ubuntu application page and click to start.
Try to start creating the simplest Node.js application "Hello World". Create an empty folder called "hello" with cmd, cd into the folder and open the folder with vscode:
mkdir hello
cd hello
Create a file in the hello folder app.js as follows:
Use the node tool to compile and run the app.js. The specific method is cd to enter the file directory where the app.js is located or use shortcut ctrl + ' in vscode to open the integrated end point of vscode (Integrated Terminal) and type the command:
node app.js
The results are as follows: