Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add arbitrary data to package.json and how?

Tags:

npm

I have a browser-based application that has a package.json (for managing dependencies using node.js).

However, I'd like to add some json meta-data to my app and I have two options: either create a new json file and add the data, or add it to the package.json.

The question is:

  1. Is it recommended to add application-specific non-standard meta-data to package.json?

  2. Where can I add this data? Under which key? _my_data seems to be a good key, but I couldn't find any standard documentation about this.

like image 575
AlexStack Avatar asked Oct 05 '13 22:10

AlexStack


People also ask

Can you add custom fields to package json?

Yes, you're allowed to add custom entries to package. json .

Can I manually add to package json?

You can add dependencies to a package. json file from the command line or by manually editing the package.

Can I modify package JSON file?

you can just open it with nano and edit it manually...

Can I use variables in package json?

To use variable, you need to declare a section named config (or something else, but not a name was already taken by the package. json ).


1 Answers

You are free to add arbitrary fields to package.json (and npm will not complain). So long as the file is valid JSON, npm will look for the relevant fields (e.g. dependencies for npm install) and won't complain about additional fields

Assuming your dependencies are standard, the "recommended" approach is to keep a separate JSON file for non-standard data. This way, you can just copy or link to the standard package.json (and you are free to use arbitrary fields in your specific JSON file)

like image 60
SheetJS Avatar answered Oct 25 '22 18:10

SheetJS