11

So oddly I really cannot find the answer to this question and after a few posts and docs I've looked at on NPM I've decided to ask the question - which may be a very basic one but doesn't seem to be implicitly addressed...

How do you uninstall npm from a dir?

Premis:

you npm init -y on the wrong directory

desired outcome:

to remove npm from that directory

I'm working on windows 10 / using git bash on VS code terminal

any help here would be appreciated -

Wally

1
  • 2
    delete .node_modules and package.json
    – user120242
    May 28, 2020 at 10:02

2 Answers 2

17

All npm init does is setting up package.json for you (guided or not). If you just del package.json from the wrong directory, you should be good to go.

4
  • Hi Kamen - thanks for the answer - such a basic solution, I would have thought that npm init would have done something more behind the scenes, so is npm init even necessary - or could you just create a package.json file manually?
    – Wally
    May 28, 2020 at 10:10
  • It's the same, npm init is just a way of doing it through the CLI. If you call it with -y, it will just init with default values with no other input from you, otherwise it will go through the needed params and ask you to input values. May 28, 2020 at 10:13
  • '-f' or '-y' ... ok thank you for the input - I know its a very basic question
    – Wally
    May 28, 2020 at 10:16
  • 1
    Not sure if I'm looking at the right thing, but it seems that all four (-f, --force, -y, --yes) are the same: github.com/npm/init-package-json/blob/latest/… May 28, 2020 at 12:54
4

Deleting the package.json from the wrong directory should do the trick.

You will have to keep in mind that if in case you have run the npm i or npm install commands after npm init you will also have to delete the node_modules folder (as it usually takes plenty of disk space) and run npm i now in the correct directory.

1
  • Agree, leaving node_modules directory is not a good idea.
    – Ravi R
    Jul 26, 2022 at 11:58

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.