UNPKG

npm-module-tutorial

Version:

An educational npm module demonstrating the fundamental steps of creating and publishing a Node.js package.

37 lines (30 loc) 1.19 kB
## Steps to make npm package * Signup https://www.npmjs.com/signup * Decide npm package which is not available on npm registry and put as package-name in package.json * create custom importable module * npm init -y * index.js `function helloNpmWorld() { return "hello NPM World" } module.exports = helloNpmWorld` #### Testing * `npm link` to make package available globally * create test.js in test folder `const helloNpm = require('package-name') console.log(helloNpm())`. * `npm link npm-module-tutorial` will create node_module and package-name in it. * run `node test.js` #### Publish npm package * `npm login` * `npm publish` #### rePublish npm package * update Patch, Minor or Major version to republish * `npm publish` ## Scoped npm package * `npm init --scope=@your-username` * package name `@your-username/package-name` * `npm publish --access public` * `npm publish --access private` ## Deprecate npm package * `npm deprecate npm-module-tutorial@"< 2.0.0" "critical bug fixed in v2.0.0"` * When will you try to install 1.0.0 npm will warn "npm warn deprecated npm-module-tutorial@1.0.0: critical bug fixed in v2.0.0" in terminal