0

I followed some similar posts about this questions but for me it doesn't seem right. I did npm init --yes and now my package.json is containning a lot of dependencies, I feel like they aren't the project dependencies but the computer dependencies.

How can I update the package.json only with the actual project dependencies ?

[edit]

Or maybe it's my node_modules that contains too many useless things, how can I update it to fit the current project ?

1
  • Please update your question with code so people can have a clearer view of what your problem is. Commented Jun 29, 2021 at 8:20

1 Answer 1

1

I assume that you have one project with node_modules folder in it and you're running npm init -y command.

If this is the case, then yes, it'll include all the packages stored in node_modules as dependencies.

contains too many useless thing

No, those are not useless but dependencies of your actual dependencies. You might try following to get actual idea.


Create a new folder, go inside the folder, create the package.json using npm and then install few dependencies.

# Create an example folder.
$ mkdir example1
# Go inside the created folder.
$ cd example1
# Create package.json file using npm.
$ npm init -y
# Install few packages.
$ npm i express morgan cors mongoose

Now, go ahead and delete both package.json and package-lock.json files and then run the npm init -y command again. You'll see more than 50 packages as dependencies instead of 4.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much for the nice input and the explanations !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.