Does package.json file require a unique name per site when used in local dev?

915 Views Asked by At

I am new to npm and have set up a test site on my local dev server. I now want to install a new project(s) in another local directory with identical dependencies to the test site by copying the package.json file from the test site to the new project and running npm install.

If the name in the test site package.json file is, for instance, "npm-site-build" can I use that same name in the new project's package.json file? Or does the name have to be unique for each project?

The docs at npmjs.com say:

The name and version together form an identifier that is assumed to be completely unique.

I assume that is only for packages that are intended to be published to npm?

1

There are 1 best solutions below

1
On BEST ANSWER

You are correct. The name specified in package.json only needs to be unique if you're running npm publish to publish your package to the npm registry. Otherwise, those two directories won't even be aware of each other and can have identical package.json files. Npm doesn't keep track of all the projects on your machine, only packages in the registry.