Node.js modules are a type of package that can be published to npm.
Overviewpackage.json
filepackage.json
file
package.json
file, on the command line, in the root directory of your Node.js module, run npm init
:
npm init --scope=@scope-name
npm init
name
and version
), as well as the main
field:
name
: The name of your module.version
: The initial module version. We recommend following semantic versioning guidelines and starting with 1.0.0
.For more information on package.json
files, see "Creating a package.json file".
Create a file with the same name you provided in the main
field. In that file, add a function as a property of the exports
object. This will make the function available to other code:
Test your moduleexports.printMsg = function() {
console.log("This is a message from the demo package");
}
Publish your package to npm:
npm publish
.npm publish --access public
On the command line, create a new test directory outside of your project directory.
mkdir test-directory
Switch to the new directory:
cd /path/to/test-directory
In the test directory, install your module:
npm install <your-module-name>
In the test directory, create a test.js
file which requires your module and calls your module as a method.
On the command line, run node test.js
. The message sent to the console.log should appear.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4