This is the sixth day of my participation in Gwen Challenge

First, Node.js past life

1.1 the Node. Js’s official website

nodejs.org/zh-cn/

I’m currently using node version V12.14.1 and NPM version 6.13.4

Install Node.js

There are two ways to install Node.js. One is to install node. js directly through the installation package, and the other is to install node. js through the Node Version Management (NVM).

NVM A program mounted and run on the command line

2.1 Downloading the Installation Package

Enter the official website: nodejs.org/zh-cn/downl… Download the 32-bit or 64-bit installation package based on the model.

2.2 installation

Note: In order for Node to run with sufficient permissions; First, run CMD as an administrator; Environment variables are automatically configured during installation, so you can enter Node directly to enter node.js interactive mode

REPL (read-eval-print-loop) interactive runtime environment, similar to the Console in Google Chrome.

Purpose: To facilitate node.js to test JavaScript code run environment;

REPL basic operations: Variables, functions, objects can be defined and run, and the underscore returns the result of the last operation and can be directly based on the result of the next operation.

REPL basic commands:.help (view common commands).exit (Exit, or press CTRL + C twice)

Execute the js file from Node.js

In real development, it’s not possible to do this through a REPL, it’s definitely based on various JS files in a project, so how does that work? There are several ways to do this, one of which is to drag the file directly to the command line, noting that node is added in front of it. As shown below:

Node.js global object – global

In js development, we define a variable that is a property of the global object window by default. What is the global object in Node.js? The global object. The default function is much like the Window object, in that all variables, functions, and objects are mounted to the Global object.

Global represents the global environment where Node resides, similar to the window object of a browser.

Global is the global namespace in Node. Any variable, function, or object is a property of global.

Variables, functions, and methods defined in a module are theoretically only available in that module, but can be passed outside the module for use in development through the require method in exports objects.

Output in the console is as follows:

Note: If a variable is declared in a js file, by default it belongs to the current file and not to global or Window. It has to be explicitly specified. As shown in the figure below