The Basics of Package.json - NodeSource
The Basics of Package.json - NodeSource
〉
The NodeSource Blog
SHARE
Search
N E XT P O ST
You have reached the beginning of time!
Solving Memory Leaks in Node.js has Never
〉
Been Easier, Introducing the Latest Version of
N|Solid
A L L P O STS / CO M M U N I T Y
The package.json file is core to the Node.js ecosystem and is a fundamental part
of understanding and working with Node.js , npm , and even modern JavaScript .
This file is used as a manifest, storing information about applications, modules,
packages, and more. Because understanding it is essential to working with
Node.js , it's a good idea to grasp the commonly found and most crucial properties
of a package.json file to use it e ectively.
This is a series, based on one of the most featured whitepapers we have done by
developers in the Node.js ecosystem. If you are interested in the complete guide,
you can get it through this link.
The 2022 guide will include this, which we will be releasing by units of knowledge
every Thursday in the following weeks. Today you are in part 1 of the guide:
3. Understanding the di erent types of dependencies and other host Specs inside
package.json
PeerDependencies
PeerDependenciesMeta
OptionalDependencies
BundledDependencies
engines
os
cpu
Inside your package.json , the name property as a string would look something
like this:
"name": "metaverse"
There are only a few material restrictions on the name property: • Maximum length
of 214 URL-friendly characters • No uppercase letters • No leading periods (.) or
underscores (_) (Except for scoped packages)
While the version property isn't required to follow semver (semantic versioning)
standards, which is the model used by the vast majority of modules and projects in
the Node.js ecosystem, it's what you'll typically find in the version property of a
package.json file.
Inside your package.json , the version property as a string using semver could
look like this:
"version": "5.12.4"
The license property of a package.json file is used to note the module that the
package.json file describes. While there are some complex ways to use the
licensed property of a package.json file (to do things like dual-licensing or
defining your own license), the most typical usage is to use an SPDX License
identifier. Some examples that you may recognize are MIT, ISC, and GPL-3.0.
Inside your package.json , the license property with an MIT license looks like
this:
"license": "MIT"
Inside your package.json , the description property would look like this:
The keywords property inside a package.json file is, as you may have guessed, a
collection of keywords that describe a module. Keywords can help identify a
package, related modules and so ware, and concepts.
The keywords property is always an array, with one or more strings as the array's
values; each one of these strings will, in turn, be one of the project's keywords.
Inside your package.json , the keywords array would look something like this:
"keywords": [
"metaverse",
"virtual reality",
"augmented reality",
"snow crash"
]
Inside your package.json , the main property, with an entry point of app.js, would
look like this:
"main": "app.js"
Inside your package.json, the repository property would look like this:
"repository": {
"type": "git",
"url": "https://github.com/bnb/metaverse.git"
}
At its simplest, the scripts property contains a set of entries; the key for each
entry is a script name, and the corresponding value is a user-defined command to
be executed. Scripts are frequently used to test, build, and streamline the needed
commands to work with a module. Inside your package.json , the scripts
"scripts": {
"build": "tsc",
"test": "standard"
}
To run scripts in the scripts property of a package.json , you'll need to use the
default npm run command. So, to run the above example's build, you'd need to
run this:
Usage:
That said, to run the test suite, you'd need to execute this:
Usage:
$ npm test
Notice that npm does not require the run keyword as part of the given script
command for some tasks like the test, start, and stop by default.
Note: You'll frequently find carets (^) and tildes (~) included with package versions.
These are the notations for version range — taking a deep dive into these is outside
the scope of this guide, but you can learn more in our primer on semver. In addition,
you may specify URLs or local paths in place of a version range.
Inside your package.json , the dependencies property of your module may look
something like this:
"dependencies": {
"async": "^0.2.10",
"npm2es": "~0.4.2",
"optimist": "~0.6.0",
"request": "~2.30.0",
"skateboard": "^1.5.1",
"split": "^0.3.0",
"weld": "^0.2.2"
},
"devDependencies": {
"escape-html": "^1.0.3",
"lucene-query-parser": "^1.0.1"
},
Remember that you can now monitor your applications and take your Node.js
journey to a professional level with N|Solid.
To get the best out of Node.js and low-cost observability, start a free trial of
N|Solid.
And if you want to find out about our latest content and product releases, these
are the channels to keep up to date with NodeSource:
↳ ↳ Nodesource's Twitter
↳ ↳ Nodesource's LinkedIn
F E AT U R E D A R T I C L E S
Solving Memory Leaks in Node.js has Never Been Easier, Introducing the Latest Version of N|Solid
In Product on Apr 29 2024
C AT E G O R I E S
Community
How To
Node.js
NodeSource
Product
STA R T F O R F R E E
© 2024 NodeSource
W H AT W E D O S O LU T I O N S LEARN CO M PA N Y
N|Solid Microservices Blog Contact Us
Product Pricing High Tra ic Resources About NodeSource
NodeSource Services Legacy Applications Support Portal Press
Internet of Things Documentation Legal
Privacy Policy