JSConf Budapest, 2016-05-12
Laurie Voss
CTO, npm Inc.
@seldo
Not @izs.
Obvious
plug for
paid product
If you get an EACCESS error, you can sudo, or you can fix your permissions with this:
https://docs.npmjs.com/getting-started/fixing-npm-permissions
Not ready for npm@3? Then:
npm install npm@lts -g
npm init --yes
npm init --scope=myusername
npm install @myusername/mypackage
require('@myusername/mypackage')
npm install --save-dev npm install -D
npm install --save npm install -S
npm install --production
Skip your devDependencies in production!
npm install --save --save-bundle
npm install --cache-min 999999
npm start npm stop npm restart npm test
{
"name": "@seldo/some-package",
"version": "1.0.0",
...
"scripts": {
"test": "mocha ./test/*.js",
"start": "node ./index.js"
}
}
Don't force users to install global tools
Don't get conflicts over global tool versions
npm publish npm publish --access=restricted npm publish --access=public
1.5.6
Breaking
Feature
Fix
Major
Minor
Patch
npm version major npm version minor npm version patch
npm version major -m "bump to version %s"
npm shrinkwrap
npm install clingwrap -g
old way: npm owner
npm team npm access
npm team create <scope>:<team> e.g. npm team create myorg:myteam npm team destroy <scope>:<team> npm team add <scope>:<team> <user> npm team rm <scope>:<team> <user> npm team ls <scope>:<team>
npm access grant read-only|read-write <scope>:<team> [package] npm access revoke <scope>:<team> [package] npm access ls-packages [user|scope|scope:team] npm access ls-collaborators [package [user]]
npm link
Work with multiple packages simultaneously
In your package "alice":
npm link
In "bob", which requires "alice":
npm link alice
npm publish --tag npm dist-tag
npm publish --tag
Publish with a tag:
npm install <package>@<tag>
Install a package at a tag:
npm install npm@next
Try out the next version of npm!
npm dist-tag add <package>@<version> <tag>
Apply a tag after publishing:
npm dist-tag rm <package> <tag>
Remove a tag:
npm dist-tag ls <package>
List tags on a package:
npm install --tag <tag>
Danger, Will Robinson!
npm unpublish npm unpublish <package>@<version>
Unpublishing is restricted after 24 hours
The kinder, gentler alternative to unpublish
npm outdated npm update
Package Current Wanted Latest Location domutils 1.3.0 1.3.0 1.5.1 @npm/testnpm handlebars 1.3.0 1.3.0 4.0.5 @npm/testnpm hbsfy 1.3.2 1.3.2 2.7.0 @npm/testnpm
npm run start npm run <anything>
npm_package_name npm_package_version npm_package_dependencies_request npm_package_dependencies_express npm_config_node_version npm_config_registry
e.g.
console.log(process.env.npm_package_name)
{
"name": "@seldo/mypackage",
"config": {
"port": "80"
}
}
> console.log(npm_package_config_port) > 80 npm config set @seldo/mypackage:port 8080 > console.log(npm_package_config_port) > 8080
publish: prepublish, publish, postpublish
install: preinstall, install, postinstall
uninstall: preuninstall, uninstall, postuninstall
version: preversion, version, postversion
test: pretest, test, posttest
stop: prestop, stop, poststop
start: prestart, start, poststart
restart: prerestart, restart, postrestart
per-project: /path/to/my/project/.npmrc per-user: ~/.npmrc global: $PREFIX/etc/npmrc built-in: /path/to/npm/npmrc
//registry.npmjs.org/:_authToken=00000000-0000-0000-0000-000000000000
Looks like:
For CI, try:
//registry.npmjs.org/:_authToken={$NPM_TOKEN}
https://remysharp.com/2015/10/26/using-travis-with-private-npm-deps
More details:
For limited values of "fun"
sign-git-tag: automatically sign every version
save: automatically install everything with --save
init-author-{name,email}: default values for npm init
cache-min: how old a local package can be before checking the registry
ignore-scripts: disable install scripts, for the paranoid
Transpile all the things!
and
greenkeeper.io
"npm outdated" as a service!
npm install nsp -g
nsp check
architecture
npm update
npm init
auto saving
.npm-init.js
devDependencies
bundledDependencies
offline installs
run scripts
publishing
SemVer
npm version
shrinkwrap
npm team
npm access
npm link
dist-tags
unpublish
deprecate
outdated
lifecycle events
.npmrc files
...and more!
laurie@npmjs.com
@seldo
You should follow me on Twitter for no reason:
Good questions get swag!