Package.json
lastmod 2023-12-04created 2020-09-2311 edits
Categories
Example
Create a package.json file in the project ROOT directory.
{
"name": "gitlab-webhook-server",
"version": "0.1.0",
"private": true,
"dependencies": {
"gitlabhook": ">= 0.0.17"
},
"scripts": {
"start": "node app.js"
}
}
To install the packages, run the npm install command in that directory.
Properties
- private
- If set to true, npm will not publish the package.
- scripts
- A dictionary containing script commands that are run at various times in the package's life cycle.
- version
- Version information.
-
version: Exactly matching version -
=version: Exactly matching version -
>version: Greater version -
>=version: Greater than or equal version -
<version: Lesser version -
<=version: Lesser than or equal version -
~version: A version range. ~0.2 means from 0.2 up to but not including 0.3 -
1.2.x: x notation is also allowed -
^version: Updates within the range that guarantees backward compatibility, following the SemVer (Semantic Versioning) convention.
-
- dependencies
- List of dependencies, installed on
npm installandnpm install --production.
- devDependencies
- List of development dependencies, installed on
npm installandnpm install --dev.
- exports
- sub path module support
Specifying a local path in dependencies
How to apply environment variables in scripts
To apply NODE_ENV=develop, do the following.
How to use package.json properties in JavaScript
- node.js - Is there a way to get version from package.json in nodejs code? - Stack Overflow
- scripts | npm Docs
Mainly used to pull out things like the version number:
However, a better approach than the one above is to use the environment variables with the npm_package_ prefix, such as process.env.npm_package_version. See the relevant documentation for details.