npm
What is the NPM
NPM stands for Node Package Manager, which stands for Node’s Package management system. Is used to manage JS.
NPM implementation ideas
- There is a remote code repository (registy) where all THE JS code that needs to be shared is stored, and each JS file has its own unique identity
- When a user wants to use a JS file, they simply reference the corresponding identity and the JS file will be automatically downloaded
Node.js
What is the Node. Js
- Node.js is a Javascript runtime environment, not a JS file
- Node.js is a Javascript runtime environment based on the Chrome V8 engine, written in C++
- Node.js is not a library, but a runtime environment, or JAVASCRIPT interpreter
Run js code in Node.js
Method 1: Run it in the interactive environment of Node.js
In the past, JS could only be run in a browser. With the advent of Node.js, it is possible to run JS code with Node.js installed, whether on a server or on a laptop. Assuming we have node.js installed, use the Node command to enter the node.js interactive environment
> node
Copy the code
After performing the action, press enter and you can see that the code executed correctly. Ctrl + D to exit the interactive environment.
Method 2: Write the code to a file and execute it using the Node command
Write js code in app.js file
console.log('hello')
Copy the code
Then run the command in the directory where the file resides
> node app.js
Copy the code
As you can see, Hello is printed on the console, independent of the browser.
When you execute Node app.js, you are actually running a Node.exe executable.
The commands in the package.json script of the vue project are also executed through Node. Each string corresponds to a script.
How Node.js works differently from browsers
Node.js and browsers are different environments, with many subtle differences.
- First, they each contain different global variables.
- The Document object is used to manipulate pages, so it can only be used directly in a browser environment. But if you’re putting it in node.js with retrograde code, don’t use document.
- HTTP objects that can be used directly in Node.js are not available in a browser environment.
- Second, node.js and browsers have different levels of support for new ES6 features.
The installation
New versions of Node.js come with NPM, which is installed with node.js when installed. NPM is used to manage the packages that Node.js depends on, or to install/uninstall node.js.
References: What is Node.js?