GitHub - pluswhite/Node-Module-Example: Example of node module, with TypeScript, Jest, ESLint, Prettier.

npm GitHub npm

1. Create package.json

Note: define your module name in name field of package.json.

2. Define a entry file

entry is a file that return object method for the require('your_module_name') call.

Can be config in main field of package.json

3. login your npm account

4. Publish your module

5. Install and Use your module

# Anthor directory
npm install your-package-name
const myModule = require('your-package-name');
myModule();

Notice:

  1. If it occurs an error message that you do not have permission to publish "your module name", Are you logged in as the correct user?, that means this module had alredy existed.
  2. If you update module and want to republish, you must update your module version file in package.json, you can use the npm cli npm version major/minor/patch.
  3. Your registry config must be http://registry.npmjs.org, or you can config it a Github npm registry by https://npm.pkg.github.com.