The basic function of npm and problem that you might face during upgrade
Published on: 13th Aug 2025
Overview
This is an utility that is available when you install Node.js. npm
stands for 'Node Package Manager' which is responsible for installing both global packages and app specific packages.
For example, when you are developing an application that uses Sqlite to store data, you may want to install the 'Sqlite driver' that handle the opening of your database, write to database or query the database. As a result, we don't need to have the low level Sqlite API knowledge.
How to use it
Install a package for your application
This can be done with the following command:
npm install better-sqlite3 --save
To see what has been installed
In the same place of your package.json of your project directory, run the following command to view what has been installed for your application:
npm ls
The package that has been installed locally is kept in node_modules
directory. You can delete the node_modules
directory and runs the following command to refresh it:
npm install
The following command is for getting the list of packages that is available to any application:
npm ls --global
or
npm ls -g
Global package means that the package will be installed once and available to any application that is running on the same computer.
The secret that lies in the npm
When you have to maintain an application that has been running for years, you may want to upgrade Node.js version. This could be due to the Node.js has reach end of life or you want to use the latest Node.js feature. In this case, upgrading Node.js to a newer version will become a bit complex.
As a result, you may want to review the current npm configuration before upgrading it.
npm config ls -l
- to view all npm settings.npm config get cache
- the location of the npm log files.npm config get prefix
ornpm prefix -g
- the location of the global packages. When using nvm (Windows), it should be 'C:\ProgramData\npm\npm'.
For your application to access the local package and global package, it needs to know the node_modules
location. For example, your local packages will be kept in the directory returned by the following command:
npm prefix
And the global package will be kept in the directory returned by the following command:
npm prefix -g
Why things broken after upgrading Node.js on Windows?
-
After installing a newer version of Node.js using nvm (on Windows), the original global packages will become inaccessible. In this case, run the following command to fix the configuration
npm config set prefix 'C:\ProgramData\npm\npm'
NOTES: you might have to review and update the global packages for compatibility issue or simply run
npm install your-global-package-name -g
to upgrade it.
Conclusion
It is always good to find out the current npm configuration before upgrading Node.js regardless Linux or Windows.
References
- For more information about npm, read this: https://docs.npmjs.com/
Related posts
Back to #NODEJS blog
Back to #blog listing