Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

package.json generation / npm unused packages

Tags:

I'm introducing unit testing in my project and for this, I need to make myself a package.json file.

First question is, which unit testing suite are you using? I'm looking forward mocha which seem to be pretty much standard for Node.js projects.

Second question is: Is there any magical way of generating a package.json file? (for dependencies and versions)

Third question is: I've been testing a lot of npm packages while developing my project and now I'm stuck with a lot of probably unused packages. Is there any way to tell which one are useless? (I saw npm list installed which is useful though)

like image 655
Tommy B. Avatar asked Apr 11 '12 15:04

Tommy B.


People also ask

How do I remove unused NPM packages from json?

json. To identify the unused package, just run npx depcheck in the project root directory. Next step is to uninstall the npm packages using npm uninstall command. The post Remove unused npm modules from package.

Should you keep NPM packages up to date?

Npm packages often get new releases (adding new functionalities, fixing bugs or vulnerabilities). It is important to keep the packages updated as much as possible during the development of your application.

What does npm prune do?

Description. This command removes "extraneous" packages. If a package name is provided, then only packages matching one of the supplied names are removed. Extraneous packages are those present in the node_modules folder that are not listed as any package's dependency list.


1 Answers

  1. I am using Mocha.

  2. npm init

  3. npm ls will list "extraneous" next to ones that are not in your package.json. But, it sounds like you don't have a package.json yet.


Basically, your workflow is very backward. Here is how it is intended to work:

  1. Start a new project with npm init. It has no dependencies.
  2. Oh, I want to start using a package, say express? Add it to package.json under dependencies, then run npm install.
  3. Oh, I want to start using a package for development, say mocha? Add it to package.json under devDependencies, then run npm install.

You seem to have some existing code with manually-installed packages (via npm install <packageName>), which is a mess. I suggest starting over and following the above workflow.

like image 66
Domenic Avatar answered Sep 28 '22 14:09

Domenic