1.1.0 • Published 9 years ago
hello-world-package v1.1.0
#Node Packaging & Publishing This tutorial talks about node packaging and publishing. I request you to read how to setting up node environment before getting into details (i.e., not covered nodejs installation here)
How do we create a node package file (package.json)?
> npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sane defaults.
See 'npm help json' for definitive documentation on these fields and exactly what they do.
Use 'npm install <pkg> --save' afterwards to install a package and save it as a dependency in the package.json file.
Press Ctrl+C at any time to quit.
name: (default-package-name) --> Package Name(check the availability)
version: (1.0.0) --> Version
author: --> Your Name
description: --> Description
test command: --> Scripts to run
git repository: --> git repo if you use
keywords: --> Keywords - useful for searching your module
license: (ISC) --> License
Finally say Ok! to create package.json
How do we create module?
Create sample index file with exporting APIs
Example
module.exports = { sayHi: function(name) { return (name ? ('Hi ' + name) : 'Nope') + '!'; } };
How do we setup npm user account?
> npm login --registry https://registry.npmjs.org/
This will prompt you to input username, password and eamil.
Also stores globally (/usr/<name>/.npmrc)
How do we publish?
> npm publish