Installation

  1. Installation should select LTS version

    Node.js The official website has two installed versions, LTS and Current.

    LTS is the long-term stable version. For the pursuit of stability and enterprise-level projects, it is recommended to install the LTS version.

    Current is the early adopter version of new features. For users who want to try new features, it is recommended to install the Current version. However, there may be hidden bugs or security holes in the Current version, so it is not recommended to use Node.js in the Current version in enterprise-level projects.

    After downloading, select all to install by default.


  2. View the version number of installed Node.js

    Open a terminal and type node -v to see the version number.


  3. Execute Javascript code in Node.js environment

    1. Open Terminal

    2. Switch to the path of the js file to be executed. You can use cd to switch to the target path, or open the target folder and enter cmd, or open the target folder and then hold shift and right-click the blank area to open powershell.

    3. Enter node js filename. Note that the file name should be written with a .js suffix.

      (There is a shortcut key tab in the terminal to quickly complete the file path. For example, there is a js file in the directory: prac1.js. Just enter node p and press tab to complete the path and filename.)


  4. nodemon

    Usefulness: When writing a Node.js project, if the code is modified, it needs to be manually closed frequently and then restarted, which is very cumbersome. The nodemon tool can monitor changes in project files. When the code is modified, nodemon will automatically restart the project for us, which greatly facilitates development and testing.

    Install (globally): npm install -g nodemon

    Startup file: nodemon js file path


Share