What is the difference between the global installation of dependencies and local installation of dependencies?

  • Global installation of dependencies is stored in /npm directory. While local installation of dependencies stores in the local mode. Here local mode refers to the package installation in node_modules directory lying in the folder where Node application is present.
  • Globally deployed packages cannot be imported using require() in Node application directly. On the other hand, locally deployed packages are accessible via require().
  • To install a Node project globally -g flag is used.
    C:\Nodejs_WorkSpace>npm install express ?g
  • To install a Node project locally, the syntax is:
    C:\Nodejs_WorkSpace>npm install express