name
As long as we do not publish the package in the repository, the field can be scored. The question is that this field is useful for naming the installation file or, for example, for displaying the product name on its web page. In general, "how do you call a yacht, .."
version
The main idea is not to forget to increase the version number when expanding the functionality, correcting errors, ... Unfortunately, in our office you can still find products with the same version 0.0.0. And then go and guess what kind of functionality works for the client ...
main
This
field tells you which file will be launched when our application starts (`npm start`). If the package is used as a dependency, which file will be imported when using our module by another application. The current directory is the directory where the `package.json` file is located.
And yet, if we, for example, use
vscode , the file specified in this field will be launched when the debugger is invoked or when the "execute" command is run.
The extension ".js" may be omitted. It is rather a consequence of all possible uses, so the documentation is not directly spelled out.
engines
This field contains a tuple: {"node":
version , "npm":
version , ...}.
I know the “node” and “npm” fields. They determine the node.js and npm versions needed for the operation of our application. Versions are checked when running the “npm install” command.
The standard syntax for determining dependency package versions is supported: without prefix (single version), the prefix "~" (the first two numbers of the version must match) and the prefix "^" (only the first number of the version must match). If there is a prefix, the version must be greater than or equal to that specified in this field.
Some containers, at least in the documentation, write that the appropriate versions will be used by default. In this case, we are talking about Azure.
Example:
"engines": { "node": "~8.11",
next "rake"
And the king is naked!
It was repeatedly agreed with the client that the required version of `node.js` should be no less than 8. When the initial versions of the application were delivered, everything worked. “One fine day” after the delivery of the new version from the client, the application stopped running. Everything worked in our tests.
The problem was that in this version we began to use functionality that was supported only starting from version 8 node.js. The “engines” field was not filled, so no one had noticed before that the client had an ancient version of node.js installed. (Azure web services default).
scripts
The field contains a tuple of the form: {"script1":
script1 , "script2":
script2 , ...}.
There are standard scripts that are executed in a given situation. For example, the “install” script will run after running “npm install”. Very convenient, for example, to check the availability of programs required for the application to work. Or, say, to compress all the static files available through our web service so that they do not have to be compressed on the fly.
You can not be limited to standard names. In order to execute an arbitrary script, you need to run "npm run
script-name ".
It is convenient to collect all used scripts in one place.
Example:
"scripts": { "install": "node scripts/install-extras", "start": "node src/well/hidden/main/server extra_param_1 extra_param_2", "another-script": "node scripts/another-script" }
PS The extension ".js" can be omitted in most cases.