- Supakon Khongkrajang
1. To see trees of dependencies
When working on projects with multiple dependencies, it's crucial to have a clear understanding of your project's dependency tree.
To see a list of all your project's dependencies and their versions, simply run
npm ls // Output email@example.com /path/to/your/project ├─┬ firstname.lastname@example.org │ ├── email@example.com │ └── firstname.lastname@example.org ├── email@example.com ├── firstname.lastname@example.org ├─┬ email@example.com │ ├── firstname.lastname@example.org │ └── email@example.com └── firstname.lastname@example.org
Use the '-g' flag to see a detailed tree view of your global dependencies.
npm ls -g
You can also tell the difference between production and development dependencies using the '--prod' and '--dev' flags.
npm ls --prod npm ls --dev
2. Check for security holes.
npm provides a built-in tool to help you analyze your project's dependencies and provide a detailed report of any known vulnerabilities, including severity levels and recommended fixes.
To check the security of your project, you just need to run
Once you know where the problems are, NPM makes it easy to fix them. by running the following command.
npm audit fix
3. Prune Your Dependencies
This command will look at your project's dependencies and remove any that aren't mentioned in your 'package.json' file. This will help keep your project lean and efficient.
If you want to remove production dependencies as well, you can use
npm prune --production
By using these three important npm tips in your development process, you can improve the speed of your work, make it easier to handle dependencies, and, in the end, make better software. Take the time to learn about these features and try them out to find out how they can help your projects. Good luck coding!