Is npm more similar to Maven or Pip in terms of functionality and usage?

I am curious about the way Javascript's npm handles dependencies in terms of installation. Does it install dependencies on an OS-wide level similar to how Python's pip operates without a virtualenv? Or does npm handle installations more like Java's mvn, which store dependencies in a local pom.xml file (making it feel like always being in a virtualenv compared to pip)?

My main question revolves around whether npm performs OS-wide installs or local installs.

Answer №1

Why not both?

  • yarn add PACKAGE_NAME installs the package globally.

  • yarn add --dev PACKAGE_NAME installs the package as a development dependency in the current directory, under node_modules/.

  • yarn add PACKAGE_NAME --save installs the package locally and saves it as a dependency in your package.json.

Take a look at this guide for more information.

Answer №2

By simply running

npm install <dependency name>
, you are instructing node to install the package only within your current directory, which will create a node_modules folder in that specific location.

If you use the command

npm install -g <dependency name>
along with the -g flag, you are indicating that you want the dependency to be installed globally, and it will be saved in the global node_modules directory. Global dependencies can often be accessed via the command line interface (CLI).

For example,

$ npm install mocha

You can run this command in the current directory where the installation is taking place or where the node_module exists.

$ $PWD/node_modules/.bin/mocha -v

Alternatively,

$ npm install -g mocha

You can then execute the command from anywhere in your directory using the terminal.

$ mocha -v

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

The AJAX request encountered an error while trying to send a POST request to the http://localhost/upload/undefined endpoint. The

I've been scouring the internet and testing for hours, but I'm still unable to identify the source of the error. I could really use some assistance here. I meticulously followed a tutorial on multiple file uploads with drag & drop functionali ...

Run each element in sequence after the page has finished loading

I am currently exploring animate.css at and I am curious if it is feasible to apply CSS animations to multiple elements sequentially upon page load. Below are the three distinct elements I aim to animate: <img src="flowers.png" data-test="bounceInDow ...

How to invoke a Struts 2 action synchronously using JavaScript

I've been attempting to use JavaScript to make a synchronous call to a Struts 2 action. Despite finding multiple examples, none of them have worked for me. The only method that has worked so far is making an asynchronous call like this: function togg ...

An issue has been encountered with the Shopify package while trying to create a Client instance

Looking for help with importing the Shopify API from NPM and setting up the client without encountering errors. Here is the code snippet: import Shopify from '@shopify/shopify-api'; const client = new Shopify.Clients.Rest('store_name_here.m ...

Tips for keeping an item consistently at the top in a React Native application

Within my flatlist, I have a card that is displayed when a user makes a post. However, the card currently appears randomly on the screen. I would like the card to always be rendered at the top of the screen whenever a user makes a post, similar to how it ...

Dealing with Javascript exceptions and sending email notifications in Django

I appreciate the traditional method of handling server-side exceptions in Django using Python. I am interested in finding a similar approach for client-side exception handling in JavaScript. So far, I have come across only one option which is DamnIT, but ...

Make a POST request using AJAX to the current page and retrieve a value using the $_POST method

I've been trying to solve this puzzle, but I can't seem to figure out what's going wrong... Here's the situation: I'm passing a value to a function and using AJAX to send this value via a POST request to the same page. Upon succes ...

Who assesses the quality of npm packages?

Recently, I've begun delving into the world of nodejs and npm in my quest to learn react native. Many tutorials stress the importance of installing packages using npm. However, I am cautious when it comes to downloading software from the Internet. The ...

Selenium is displaying outdated PageSource information and is failing to refresh after running Javascript

I am working on a console program in C# where Selenium is used to control a Chrome Browser Instance, and my goal is to extract all the links from a page. However, I have encountered an issue where the PageSource retrieved by Selenium differs from the actu ...

What is the best way to include all the selected items from a multi-select list when updating my view model?

I am currently developing a website using ASP.Net Core 2.1 MVC. Within one of my views, I have implemented two multi-select lists to enable users to assign individuals to a site. The left-hand list displays all unassigned users, while the right-hand list ...

What is the best approach for looping through this JSON data?

After retrieving the following JSON data from a database using ajax: {"route":[{"latitude":-27.38851,"longitude":153.11606},{"latitude":-27.47577,"longitude":153.01693}]} What is the best approach for iterating over it to extract latitude and longitude p ...

What is the best way to merge multiple getServerSideProps wrappers?

In my NextJs app, I am integrating two libraries: next-firebase-auth and next-redux-wrapper. Each library requires me to wrap the getServerSideProps function with its own specific logic. Here's how it looks for next-firebase-auth: export const getSer ...

Storing a collection (of 'keywords') in MongoDB with Mongoose

Currently, I am experimenting with Mongoose and facing some challenges when it comes to saving data to an array. Specifically, I have an input field on a webpage where users can enter comma-separated tags. After obtaining these tags from req.body.tags, rem ...

I encounter issues when entering conditions in my JavaScript code

Being new to JavaScript, I'm trying to save the Vector position and use two buttons (forward and backward) to move the Camera to that specific location. I also attempted to incorporate 'gsap' for smooth movements, but unfortunately, the code ...

Unable to launch Heroku on the local machine

Can anyone help me figure out this error I keep encountering when attempting to start Heroku locally? [WARN] No ENV file found 15:23:12 worker.1 | C:\Users\Marija\Documents\Projects\project\node_modules\natural\l ...

Modifying the values of array elements in MongoDB

I am currently attempting to modify specific elements within an array. This particular array consists of objects that have two distinct fields. The displayed output from my view is as follows: Each line in the display corresponds to the index of the objec ...

When trying to search for 'elForm' using the 'in' operator within the context of a "datetime" type, the error "Unable to find 'elForm' in undefined" occurs

I am attempting to implement a datepicker with time options from Element UI. I am encountering an issue within the ElementUI component. It functions correctly if the type option is set as date, but throws an error with datetime. Below is my code snippet an ...

What is the process for deselecting text from a text field?

After performing a search and displaying the results on my search form, I've noticed that the text query in the textfield is being marked as selected text even though I don't want it to be. How can I prevent this? Fiddle 1) What is the best app ...

Embed a variable within the append function of jQuery

I am attempting to add multiple divs inside another div using a for loop in jQuery. The goal is to assign a unique ID to each div based on the iteration value of i. I have attempted to concatenate the value of i within the string, but it has not been succe ...

Issue with Collapse Feature on Bootstrap 3.x Navbar

The Bootstrap 3 Navbar expands properly in full screen and on a browser with a small width on a desktop PC and mobile browsers, but when using the Toggle navigation button, it doesn't slide down. I have tried to replicate the code from this example: h ...