IT:AD:NPM:HowTo:Create a package.json File
- See also:
Summary
NPM manages the packages needed in your project using a package.json file.
Process
After using a IT:AD:CLI to navigate to your project's directory, you can create one by hand:
{
"name": "Foo",
"version": "0.0.1",
"devDependencies": {
"grunt": "~0.4.1"
}
}
Basic concepts:
* name and version are required, and form the identity of the package.
* name: an url safe string. Should not include '.js' (js is implied as you are using npm).
* version: a string. Should be updated for each package release.
* description: a string description
* keywords: an array of string keywords of your choosing
* homepage: an string url the project homepage
* license: a string of the license spdx (“MIT”, etc.)
* author:
- An object:
{"name":"foo", "email":"foo@foo.com", "url":"//foo.com"}
* contributors: an array of objects. [{"name":"foo", "email":"foo@foo.com", "url":"//foo.com"}...]
* files: name of file, or folder containing files.
* main: the primary file.
* bin: files to register in the PATH.
* dependencies: https://www.npmjs.org/doc/files/package.json.html#dependencies
Using Grunt Init
Or you can use grunt init to create the file – but it's more verbose:
{
"name": "Foo",
"version": "0.0.1",
"description": "A footuristic solution",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Sky",
"license": "ISC"
}
Going Further
The specs for a package.json file can be found at the NPM site: * https://www.npmjs.org/doc/files/package.json.html