Exploring the installation directory for modules in Node.js and npm

After utilizing Node.js and npm for a few weeks with success, I've begun to question the best practice for installing local modules. Despite understanding the Global vs Local argument, my concern is more about where to store a local install. For example, if my project is located at ~/ProjectA/ and is collaborated on by multiple developers, where should local modules be placed? Initially, I simply installed the necessary modules in a default terminal, resulting in an installation path of ~/node_modules. This forced other developers to also install the modules on their own machines in order to run the application. Surprisingly, some developers were able to run the app without any issues after running npm install, which may be related to how Node.js and require() function.

Now that the project is progressing beyond experimentation, I want to set up the project folder correctly. Should the modules be installed at ~/ProjectA/node_modules and included in the version controlled files, or should they remain at a developer-specific location? Or does it not make much difference? I'm seeking "best-practice" advice and insights on how others handle setting up projects.

Answer №1

In my experience, it is considered a "best practice" to maintain project dependencies within the project folder.
The majority of Node projects I have encountered (I have been working as a Node developer for about 8 months now) follow this approach.

It is not necessary to include dependencies in version control. This is how I handle dependencies in my Node projects:

  1. Ensure that versions are specified and locked in the package.json file to ensure consistency among all team members, or utilize the npm shrinkwrap command at the project root.
  2. Add the node_modules folder to the ignore list of your Version Control System (VCS). In my case, I use git, so it goes into my .gitignore file.
  3. Celebrate, you're all set!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountered a build failure caused by conflicts amongst my dependencies

I'm encountering a build error and need assistance with the following issue: Failed to compile ./node_modules/material-ui-search-bar/lib/components/SearchBar/SearchBar.js Module not found: Can't resolve '@material-ui/core/IconButton' i ...

Whoops! The input buffer seems to be containing an image format that is not supported while attempting to utilize Next JS next-opt

I initially used the default Image Optimization component in my Next JS app, only to realize that the site could only be hosted on Vercel and not on other web hosting platforms. This limitation prompted me to explore the next-optimized-images package, whic ...

Troubleshooting: Node.js Express Server GET Handler Failing to Function

Recently, I've been attempting to build a GET request handler in Express.js. Here's the snippet of code I've put together: // include necessary files and packages const express = require('./data.json'); var app = express(); var m ...

Navigating Svelte using Express in a Node.js environment

Greetings, I have a somewhat hesitant question that I haven't been able to find an answer to online: Currently, I am operating a nodejs express Server which is responsible for rendering my views. Here is an example of how it's done: router.get( ...

The promise of a MongoDB connection with Node.js returns as 'awaiting fulfillment'

Greetings to all! A few weeks ago, I embarked on the journey of learning javascript, node.js and mongo. As a beginner, I have an interesting task at hand today. My goal is to add a simple document to the mongoDB and perform a conditional check. So here&apo ...

Execute the node script when the VSCode extension is in use

I have been working on developing a VSCode extension utilizing the power of the Language Server Protocol (LSP). This extension is designed to activate whenever a user opens a file with the extension '.ext'. The setup I have in place looks like th ...

Incorrect Reactjs installation technique

When I try to run create-react-app on my Windows PC, only dependencies are being installed with no folders other than node_modules. Even when using Yarn, I haven't been able to progress further. Please assist and thank you in advance for any help. Thi ...

When running `npm install @babel/cli`, warnings appeared for four deprecated modules. What steps can be taken to resolve these deprecations?

Overview of my current setup Operating System: MacOS Catalina 10.15.4 (latest) nvm Version: 0.35.3 (latest) node.js Version: 12.16.3 (latest LTS) - Installed using nvm directories npm Version: 6.14.4 (latest) - Installed using nvm directories Note: Avoi ...

Executing the command "npm run script" produces no results

I find it strange that I have the following scripts in my package.json file: "scripts": { "lint": "./node_modules/tslint/bin/tslint src/js/**/*", "lint:fix": "./node_modules/tslint/bin/tslint src/js/**/* --fix" }, When I execute npm run lint, I do ...

What is the best way to make `npm prune --production` work in a recursive manner?

It seems like a simple task, yet I am unable to find any information online. When running npm prune --production, it only removes the direct devDependencies from the current package's node_modules folder. Unfortunately, it does not recursively remove ...

Guide on deploying a personalized SDK alongside your nodejs application on the Azure platform

I have created an SDK.js to simplify the usage of my API on Azure, which is supported by my nodejs server. What is the most efficient method for deploying this SDK.js to the server so that clients can easily incorporate it into their code using a script t ...

Struggling with Setting Up a MongoDB Database Using Mongoose

My goal is to set up a database in MongoDB using npm Mongoose and Robomongo as my GUI. I followed the MongoDB Quickstart Docs from http://mongoosejs.com/docs/index.html, but encountered an issue where the database wasn't showing up in Robomongo. Essen ...

Utilize the request module to fetch JSON data and then deliver the desired output

Utilizing the request module for handling HTTP requests in Node.js has proven to be quite handy. Here's a snippet of code showcasing its usage: module.exports.getToken = function(){ var token ; request(validLoginRequest, function(err,resp,b ...

A TypeError has occurred due to unescaped characters in the request path, caused by [ERR_UNESCAPED_CHARACT

On my Ubuntu system, I am receiving incoming HTTP requests from the URL below: http://<MY-IP>:3000/v1/projects/list Description: The issue I'm facing is that when I make the request, I encounter the following error in the terminal: TypeError [ ...

Received an error when attempting to run "npm install" in the angular-phonecat directory

Encounter Error: > [email protected] postinstall D:\prem\angular\angular-phonecat > bower install bower ENOGIT git is not installed or not in the PATH npm ERR! Windows_NT 6.1.7600 npm ERR! argv "C:\\Program Files&bsol ...

Make sure to pass the req.user.username when redirecting to success in Passport.js

Upon successful user login, I aim to redirect them to a route that includes their username as a parameter: router.post("/login", checkNotAuthenticated, passport.authenticate("local", { successRedirect: "/dashboard/" + req. ...

It has been quite the challenge trying to integrate Argon2 with Angular 8 on MacOS, as it seems completely non-functional at the

I am currently using: MacOS Mojave Angular 8 node v12.12.0 npm v6.13.4 and attempting to implement Argon2 in my Angular 8 application. To utilize Argon2, it is necessary to globally install gcc and node-gyp. I followed the instructions on Argon2's ...

AngularJS - Import and save CSV files

I have set up a nodeJS program as the server and an AngularJS web application as the client. For generating CSV files, I am utilizing the "express-csv" library (https://www.npmjs.com/package/express-csv) Below is the code for the server side: Definition ...

npm encountered an error or issue during the installation process

I have configured my proxy settings in the .npmrc file, but I am encountering errors when running the npm install command: $ npm install npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\Program Files\nodejs\node.exe" "C:\Program File ...

While running the npm build, I encountered a mistake

https://i.stack.imgur.com/05GhH.png I transferred my Nuxt project to a Linux server using Git, then ran 'npm upgrade nuxt' and 'npm run build'. However, I hit a snag during the building process. What steps should I take next? Below is ...