package.jsonContains info on package...
npm initmyprojectcd myprojectnpm init{
"name": "myproject",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "Sequoia McDowell <sequoia.mcdowell@gmail.com> (http://sequoia.makes.software/)",
"license": "ISC"
}
init.author.name=Sequoia McDowell
init.author.email=sequoia.mcdowell@gmail.com
init.author.url=http://sequoia.makes.software/
npm confignpm config set init.author.name [your name]npm config set init.author.email [your email]cat ~/.npmrcIn myproject/:
index.jsconsole.log('hello world') in itnode ." to run index.js
index.js app.jsnode ." to run app.jsnpm install
npm installnpm install foo: installs packagenpm install --save foo: ... & saves dependencynpm remove [--save] foo: remove packagenpm install: installs this packageIn myproject/:
npm install chalk
Use our dependency:
//npm/start/myproject/app.js
console.log(chalk.green.underline('Hello World!'));
console.log(chalk.red.bold('Hello Again!'));
Run the file
Hints:
In myproject/:
rm -rf node_modulesnpm installnode .In myproject/:
npm install --save chalk
package.dependenciesList of packages (and versions) required by our package
...
"dependencies": {
"chalk": "^1.1.1"
}
...
node_modules/chalk/package.json
...
"dependencies": {
"ansi-styles": "^2.1.0",
"escape-string-regexp": "^1.0.2",
"has-ansi": "^2.0.0",
"strip-ansi": "^3.0.0",
"supports-color": "^2.0.0"
},
...
node_modules/chalk/package.json
...
"devDependencies": {
"coveralls": "^2.11.2",
"matcha": "^0.6.0",
"mocha": "*",
"nyc": "^3.0.0",
"require-uncached": "^1.0.2",
"resolve-from": "^1.0.0",
"semver": "^4.3.3",
"xo": "*"
}
...
"Semantic Versioning"
3.10.23
3: Major Version10: Minor Version23: Patch Version>=2.32.*1.2.7~3.1 (3.1.*)^3.1.9 (3.* + >=3.1)npm searchUp Next: Global Installs
npm install -g foo
Installs to privileged location (/usr/local/bin)
Make NPM install globals in our home directory
npm set prefix /your/home/npm_packages
Don't do this if you used nvm to install node!!
npm install -g nodemonnodemon /path/to/myprojectmyproject/app.js & save the filepackage.binLike package.main but for command-line usage:
"main": "index.js",
"bin" : "bin/index.js"
"bin" : {
"ccc" : "dist/cli/do_this.js",
"jsfoo":"dist/cli/foo.js"
}
Up Next: npm scripts
https://docs.npmjs.com/misc/scripts
package.jsonnpm run scriptname...
"scripts": {
"bbl-build": "babel src --out-dir dist",
"build": "npm run bbl-build",
"postinstall": "npm run build",
"start": "node . --httpauth ../presentations.htpasswd",
"debug": "PORT=3030 DEBUG=app:*,express:* npm run start",
"pretest": "echo \"about to start tests...\"",
"test": "echo \"Error: no test specified\" && exit 1"
},
...
In myproject/:
cowsay local to projectpackage.json that runs cowsay Hellonpm run helloHints:
npm run hello runs a script named hello