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.

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?

Conclusion

It is always good to find out the current npm configuration before upgrading Node.js regardless Linux or Windows.

References

Related posts

Back to #NODEJS blog

Back to #blog listing