Change Default NPM License

| Comments

Npm has a fantastic init tool for creating the descriptor for your project. It will gladly provide defaults for you. These are sometimes helpful. Wouldn’t it be more better to define your own defaults?

NPM

Npm Init

If you’re doing any JavaScript development, NPM is likely a helpful tool for your toolbox. To add a descriptor with meta information, including things like 3rd-party project dependencies, you need a package.json for your project. To get this file, you can edit it by hand or have one generated for you. To generate it, run:

1
npm init

You will then be prompted to answer a series of relevant questions, such as:

1
2
3
4
5
6
7
8
9
10
name: (hello-riot)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
...

The values in parenthesis are the defaults. Defaults are determined from things like the directory you’re in, the git repository you’re in, etc.

Set Npm Init Defaults

Some defaults are just the NPM-provided conventions. They don’t know much more to provide. But you can provide your own defaults for your system by editing ~/.npmrc. Or you can use the cli to add to this file from the terminal. For instance, the two I like to change are my author name and the license:

1
2
npm config set init-author-name "jaketrent"
npm config set init-license "MIT"

Now, you can init and just take the defaults without pressing enter to answer the question with:

1
npm -y

And what you get are the defaults you’ve already decided you like.

To know what other things you can change as defaults, use npm help 7 config and grep for init--prefixed values. Happy npm’ing!

Comments