Questions tagged [package.json]

All npm packages contain a file, usually in the project root, called package.json. This file holds various metadata relevant to the project. This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies.

All npm packages contain a file, usually in the project root, called package.json. This file holds various metadata relevant to the project. This file is used to give information to npm that allows it to identify the project as well as handle the project's dependencies.

It can also contain other metadata such as a project description, the version of the project in a particular distribution, license information, even configuration data, all of which can be vital to both and to the end users of the package. The file is normally located at the root directory of a project.

{
  "name" : "express",
  "version" : "0.0.0",
}

The name field is the name of your project. The version field is used by to make sure the right version of the package is being installed. Generally, it takes the form of major.minor.patch where major, minor, and patch are integers which increase after each new release.

For more details see the package.json documentation at npmjs.com.

3428 questions
5155
votes
20 answers

What's the difference between tilde(~) and caret(^) in package.json?

After I upgraded to the latest stable node and npm, I tried npm install moment --save. It saves the entry in the package.json with the caret ^ prefix. Previously, it was a tilde ~ prefix. Why are these changes made in npm? What is the difference…
Fizer Khan
  • 88,237
  • 28
  • 143
  • 153
2827
votes
17 answers

What's the difference between dependencies, devDependencies, and peerDependencies in NPM package.json file?

This documentation answers my question very poorly. I didn't understand those explanations. Can someone say in simpler words? Maybe with examples if it's hard to choose simple words? Also added peerDependencies, which is closely related and might…
Vitalii Korsakov
  • 45,737
  • 20
  • 72
  • 90
887
votes
31 answers

Is there a way to get version from package.json in nodejs code?

Is there a way to get the version set in package.json in a nodejs app? I would want something like this var port = process.env.PORT || 3000 app.listen port console.log "Express server listening on port %d in %s mode %s", app.address().port,…
Abhik Bose Pramanik
  • 9,181
  • 4
  • 16
  • 10
620
votes
32 answers

SyntaxError: Cannot use import statement outside a module

I've got an ApolloServer project that's giving me trouble, so I thought I might update it and ran into issues when using the latest Babel. My "index.js" is: require('dotenv').config() import {startServer} from './server' startServer() And when I…
user3810626
  • 6,798
  • 3
  • 14
  • 19
610
votes
13 answers

How to find unused packages in package.json?

Is there a way to determine if you have packages in your package.json file that are no longer needed? For instance, when trying out a package and later commenting or deleting code, but forgetting to uninstall it, I end up with a couple packages that…
Josh C
  • 7,461
  • 3
  • 24
  • 21
587
votes
21 answers

How to set environment variables from within package.json?

How to set some environment variables from within package.json to be used with npm start like commands? Here's what I currently have in my package.json: { ... "scripts": { "help": "tagove help", "start": "tagove start" } ... } I…
dev.meghraj
  • 8,542
  • 5
  • 38
  • 76
470
votes
4 answers

How do I decide whether @types/* goes into `dependencies` or `devDependencies`?

I use TypeScript 2 in my project. I'd like to use some js library, but also typings for that library. I can install types with simple npm install @types/some-library. I'm not sure if I should --save or --save-dev them. It seems to me that even…
kamyl
  • 5,938
  • 4
  • 23
  • 29
428
votes
36 answers

Start script missing error when running npm start

I'm receiving this error when trying to debug my node application using the npm start command. Error: npm ERR! Windows_NT 6.3.9600 npm ERR! argv "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js"…
Andrew Moll
  • 4,903
  • 2
  • 13
  • 15
337
votes
43 answers

Field 'browser' doesn't contain a valid alias configuration

I've started using webpack2 (to be precise, v2.3.2) and after re-creating my config I keep running into an issue I can't seem to solve I get (sorry in advance for ugly dump): ERROR in ./src/main.js Module not found: Error: Can't resolve…
Matthew Herbst
  • 29,477
  • 23
  • 85
  • 128
315
votes
8 answers

Move a module from devDependencies to dependencies in npm package.json

Is there any short command to move a module from devDependencies to dependencies in package.json? I find myself always doing this: npm uninstall --save-dev npm install --save Is there a shorter approach to this?
Emad Emami
  • 6,089
  • 3
  • 28
  • 38
285
votes
8 answers

How to use private Github repo as npm dependency

How do I list a private Github repo as a "dependency" in package.json? I tried npm's Github URLs syntaxes like ryanve/example, but doing npm install in the package folder gives "could not install" errors for the private dependencies. Is there a…
ryanve
  • 50,076
  • 30
  • 102
  • 137
285
votes
13 answers

npm install private github repositories by dependency in package.json

I'm trying to install github private repository by npm that includes other private github repositories as dependency. Have tried a lot of ways and posts but none is working. Here is what i'm doing : npm install…
vashishatashu
  • 7,720
  • 7
  • 29
  • 34
274
votes
3 answers

Do I need both package-lock.json and package.json?

After updating my NPM to the latest version (from 3.X to 5.2.0) and running npm install on an existing project, I get an auto-created package-lock.json file. I can tell package-lock.json gives me an exact dependency tree as opposed to…
Omri Luzon
  • 3,975
  • 6
  • 20
  • 29
259
votes
7 answers

How do I add a custom script to my package.json file that runs a javascript file?

I want to be able to execute the command script1 in a project directory that will run node script1.js. script1.js is a file in the same directory. The command needs to be specific to the project directory, meaning that if I send someone else the…
Jake.JS
  • 3,266
  • 3
  • 15
  • 18
252
votes
17 answers

How to display the app version in Angular?

How do I display the app version in Angular application? The version should be taken from package.json file. { "name": "angular-app", "version": "0.0.1", ... } In Angular 1.x, I have this html:

<%=version %>

In Angular, this is not…
Zbynek
  • 5,673
  • 6
  • 30
  • 52
1
2 3
99 100