23.03.2020 Views

node-js

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

When you set a package version using one of the npm commands above, npm will modify the

version field of the package.json file, commit it, and also create a new Git tag with the version

prefixed with a "v", as if you've issued the command:

git tag v3.1.4

Unlike other package managers like Bower, the npm registry doesn't rely on Git tags being created

for every version. But, if you like using tags, you should remember to push the newly created tag

after bumping the package version:

git push origin master (to push the change to package.json)

git push origin v3.1.4 (to push the new tag)

Or you can do this in one swoop with:

git push origin master --tags

Setting up a package configuration

Node.js package configurations are contained in a file called package.json that you can find at the

root of each project. You can setup a brand new configuration file by calling:

npm init

That will try to read the current working directory for Git repository information (if it exists) and

environment variables to try and autocomplete some of the placeholder values for you. Otherwise,

it will provide an input dialog for the basic options.

If you'd like to create a package.json with default values use:

npm init --yes

# or

npm init -y

If you're creating a package.json for a project that you are not going to be publishing as an npm

package (i.e. solely for the purpose of rounding up your dependencies), you can convey this intent

in your package.json file:

1. Optionally set the private property to true to prevent accidental publishing.

2. Optionally set the license property to "UNLICENSED" to deny others the right to use your

package.

To install a package and automatically save it to your package.json, use:

npm install --save <package>

The package and associated metadata (such as the package version) will appear in your

dependencies. If you save if as a development dependency (using --save-dev), the package will

instead appear in your devDependencies.

https://riptutorial.com/ 260

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!