About NPM:
NPM is a NODEJS package management and Distribution tool. It makes it easier for JavaScript developers to share code and common code snippets, and it's convenient and easy to manage your shared code through NPM.
A Nodejs installation and NPM management
Installation
Go to nodejs official website, download installation package to install directly. Also Nodejs contains the NPM module by default. The latter needs to be updated to the latest version. -V View version information, there is a successful installation. Some versions do not support read-v parameter case sensitivity, such as an error attempt uppercase-V.
Node-v
v4.4.4
npm-v
2.15.1
Update NPM Module
The-g parameter represents a global installation, and all installed module files under Windows are generally stored in the node installation directory or under the C:\Users\Administrator\AppData\Roaming cache directory.
Remove-g local installation, NPM in the current directory to create a new Node_modules directory, the downloaded module is stored inside.
Unloading
Removing modules from the Node_modules directory via uninstall
#本地卸载
npm Uninstall <name>
#全局卸载
npm Uninstall <name> g
Two create the first Nodejs application
Use the Express module to create an application.
First download the Express module
NPM Install-g Express
Express-v
Similarly, check to see if the installation was successful. There are also two parameters:-E or--ejs;-j or--jshtml. Meaning:
-E,--ejs add Ejs engine support Add Ejs module engine support
-j,--jshtml add jshtml engine support (defaults to Jade) adding jshtml template engine support
The new version Express does not support the cmd command line, so the above express-v will be an error: not internal or external command, download Express-generator
NPM install-g Express-generator
You can then use the Express command globally, and choose a folder (F:\Project\Nodejs) to create the application:
Express Hello_world
CD Hello_world into the project
CD Hello_world
# View directory structure
dir
#像这样
# 2016/06/26 14:43 <DIR> .
# 2016/06/26 14:43 <DIR>.
# 2016/06/26 01:41 1,442 app.js
# 2016/06/26 01:41 <DIR> bin
# 2016/06/26 01:41 331 Package.json
# 2016/06/26 01:41 <DIR> public
# 2016/06/26 01:41 <DIR> Routes
# 2016/06/26 01:41 <DIR> views
# 2 files 1,773 bytes
# 6 Directories 161,019,293,696 Free Bytes *
Note that there is a Package.json file in which the dependencies attribute specifies the module on which the current project depends. Before starting, you need to perform npm install download them:
NPM Install
If you do not have a Package.json file, this step will cause an error:
NPM err! Install couldn ' t read dependencies
NPM err! Windows_NT 6.1.7601
The default can be generated through the NPM INI. Here, the command is called internally by the Express Hello_world command above, and the resulting file content resembles this:
{
' name ': ' Hello_world ', '
version ': ' 0.0.0 ',
' private ': true,
' scripts ': {
' start ': ' Node./bin/ www "
},
" dependencies ": {"
body-parser ":" ~1.15.1 ",
" Cookie-parser ":" ~1.4.3 ",
" Debug ":" ~ 2.2.0 ","
Express ":" ~4.13.4 ",
" Jade ":" ~1.11.0 ",
" Morgan ":" ~1.7.0 ",
" Serve-favicon ":" ~2.3.0 "
}
}
You can also install the above template and receive the Create Package.json file. It is worth mentioning that a NPM module Package.json file contains far richer information than here.
Wait for the dependent library download to complete. After completion, one more Node_modules folder is used to save the dependent libraries.
At this point, the current application preparation is complete. Start Application:
NPM start
Enter 127.0.0.1::3000 (default port) access in the browser
Three summary
Personal experience, I hope to provide a reference for students from zero to the creation of a NODEJS application.
The above is a small series for you to bring the introduction of nodejs--will see all the content, I hope that we support cloud Habitat Community ~