NodeJS has extensive tripartite module, with these modules, you can quickly develop a variety of applications. This uses Nodejs can be very convenient and fast development.
1, install and load the kernel module, the tripartite
Use npm can search, install, uninstall module.
Example:
Search Module
By: npm search module name
In general, the search will be a lot of content, you can use regular expressions to match in order to find they are most needed, Search, such as:
npm search /^express$/
Install the module:
npm install the module name
After installation, you can use require statements to load:
2, create our own modules
We can use the Node, three-way module, of course, can create our own modules.
Embodiment, a simple write module, as follows:
This module provides two methods: method1 hello1 return character, method2 hello2 return character. Save as module.js
And then call it in another file, the calling code:
"./" refers to a module loaded in the local path.
The above loading omitted .js, may be written as: var module = require ( "./ module.js");
Look at the implementation:
3, uninstall module
Will be cached, any time you can easily use the module loaded.
But sometimes, for some modules, if you do not want to continue to use. You can be uninstalled.
Or in an external module update, you need to get the module content updates? Well, here we need to uninstall module to reload.
Unloading module code is as follows:
resolve can get the full path of the module. When the uninstall from the cache, you need to use the full path.
Implementation of the results:
It can be seen uninstalled successfully.
This reference: