[deployment] How do I install package.json dependencies in the current directory using npm

I have a web app: fooapp. I have a package.json in the root. I want to install all the dependencies in a specific node_modules directory. How do I do this?

What I want

Lets say I have two widget dependencies. I want to end up with a directory structure like this:

node_modules/
  widgetA
  widgetB
fooapp/
  package.js
  lib
  ..

What I get

when I run npm install fooapp/ I get this:

node_modules/
  fooapp/
    node_modules/
      widgetA
      widgetB
    package.js
    lib/
    ..
fooapp/
  package.js
  lib/
  ..

npm makes a copy of my app directory in the node_modules dir and installs the packages inside another node_modules directory.

I understand this makes sense for installing a package. But I don't require() my web app inside of something else, I run it directly. I'm looking for a simple way to install my dependencies into a specific node_modules directory.

This question is related to deployment node.js dependencies npm

The answer is


In my case I need to do

sudo npm install  

my project is inside /var/www so I also need to set proper permissions.


Just execute

sudo npm i --save

That's all


Examples related to deployment

error: This is probably not a problem with npm. There is likely additional logging output above Deploying Maven project throws java.util.zip.ZipException: invalid LOC header (bad signature) repository element was not specified in the POM inside distributionManagement element or in -DaltDep loymentRepository=id::layout::url parameter "Untrusted App Developer" message when installing enterprise iOS Application How do I copy directories recursively with gulp? How to deploy correctly when using Composer's develop / production switch? Enterprise app deployment doesn't work on iOS 7.1 Can not deserialize instance of java.lang.String out of START_OBJECT token Run command on the Ansible host Error when deploying an artifact in Nexus

Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`

Examples related to dependencies

Upgrading React version and it's dependencies by reading package.json How do I deal with installing peer dependencies in Angular CLI? RHEL 6 - how to install 'GLIBC_2.14' or 'GLIBC_2.15'? Automatically create requirements.txt node.js TypeError: path must be absolute or specify root to res.sendFile [failed to parse JSON] MavenError: Failed to execute goal on project: Could not resolve dependencies In Maven Multimodule project npm install private github repositories by dependency in package.json Find unused npm packages in package.json Failed to load c++ bson extension Maven dependency update on commandline

Examples related to npm

What does 'x packages are looking for funding' mean when running `npm install`? error: This is probably not a problem with npm. There is likely additional logging output above Module not found: Error: Can't resolve 'core-js/es6' Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean` What exactly is the 'react-scripts start' command? On npm install: Unhandled rejection Error: EACCES: permission denied Difference between npx and npm?