Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.
When you run npm install <packagename> in an empty folder, npm normally creates package.json, package-lock.json, and node_modules. Sometimes that does not happen.
This is due to how npm resolves the project root. For example:
npm install my-prime
In an empty folder, this normally creates package.json, package-lock.json, and installs the package in node_modules.
If that does not happen, npm may have found a package.json or node_modules in a parent directory (or higher in the tree) and used that as the project root instead—for example if you ran the command from your home directory.
npm will walk up the folder tree checking for a folder that contains either a package.json file, or a node_modules folder. If such a thing is found, then that is treated as the effective “current directory” for the purpose of running npm commands.
To fix this, either remove the parent package.json and node_modules if they were created by mistake, or run npm init -y in your folder to create a new package.json, then run npm install <package> again.