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)
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.
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.
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.
I am using Mocha.
npm init
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:
npm init
. It has no dependencies.express
? Add it to package.json
under dependencies, then run npm install
.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With