chapter
NPM is Node.js package (or modules) Manager.
www.npmjs.com have massive package on Node.js, available for free download.
When installing Node.js, NPM program will be installed.
What package / package is?
Package / package contains all the files needed for a module.
Modules can be imported into the JavaScript library used in the project.
Download Package
Download package is very simple. In the command line, execute npm insall 包
the command.
Download and install the named upper-case
package:
Kevin@QIKEGU G:\qikegu\nodejs> npm install upper-case
Now that you have downloaded and installed the first package!
NPM will be in the current directory, create a file named "node_modules" folder, the package will be placed on them. All future installation of the package will be placed in this folder.
The directory structure is shown below:
G:\qikegu\nodejs\node_modules\upper-case
Use Package
Once the package is installed, it can be used.
Introduced using "upper-case" package:
var uc = require('upper-case');
Node.js to create a file, the output "Hello World!" To uppercase letters:
Examples
var http = require('http');
var uc = require('upper-case');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(uc("Hello World!"));
res.end();
}).listen(8080);
Save the above code as "demo_uppercase.js" file, use the Node launch the file:
Start demo_uppercase:
G:\qikegu\nodejs>node demo_uppercase.js
Open your browser to view the results URL: HTTP: // localhost: 8080