Ensure only dependencies are in node modules and not dev dependencies - npm

I have a script in my package.json like so:
"build": "npm install && npm prune --production"
This command will install all dependencies and then remove the devDependencies.
Is there a command to do this in one hit? For example, a command that ensures that production-level dependencies are the only ones existing in node_modules?

The solution is npm install --only=prod.

Related

package.json disable "npm install"

Is there any way to disable the command npm install or npm i on a project through the package.json config?
I'm using yarn to add and install npm dependencies, and I want to force to not use npm install

How to manage a non-node module as dependency for Node Project thorugh NPM?

I was using bower in my project for dependency management. But now I wanted to move to node and npm. But the problem is few of my dependencies are not node modules like Smooth-Div-Scroll1 and swiftype-search-jquery2
How to manage all those dependencies in my node project. When I tried doing
"swiftype-search-jquery": "git#github.com:swiftype/swiftype-search-jquery.git",
"smooth-div-scroll": "git#github.com:tkahn/Smooth-Div-Scroll.git",
it is not able to download dependency and throw error
npm ERR! code ENOPACKAGEJSON npm ERR! package.json Non-registry package missing package.json: swiftype-search-jquery#git+ssh://git#github.com/swiftype/swiftype-search-jquery.git. npm ERR! package.json npm can't find a package.json file in your current directory.
These dependencies don't have package.json in their folder.
I don't think it's possible.
Here is a guide to migrate from bower to npm, it's pretty easy.
https://codecraft.tv/courses/angularjs-migration/step-2-typescript-and-webpack/converting-bower-to-npm/
Yup, It is not possible with NPM but at the same time, it is possible with Yarn without making any change. Instead of "npm install" we have to use "yarn install" .
Add dependencies with git url which is not present with NPM .

How to add npm module without changing old dependencies in package-lock.json?

I use npm ci to install npm modules and it install same package versions as in package-lock.json
And now I need to add npm module for starting write unit tests, I use this command: npm i jest
I expect that it should add only jest dependencies, but npm update all out-of-date dependencies of 3-5 level dependencies in package-lock.json
I would like to do something like this npm ci --save-dev jest
How to install npm package without changing old dependencies in package-lock.json?
UPD For example, please clone this repo, after that use npm ci and npm i empty-module, if you look at git diff you'll see a lot of changes of package-lock.json file

How to recursivelly npm install all dependencies

I have many package.json files in my application. Each module has its own dependencies written in its own package.json. How can I install all dependencies at once?
I tried to run npm install and it installed dependencies only according to package.json in directory where i ran npm install
You can use npm prefix parameter:
npm i --prefix <nested_dir_name>
For the following project structure:
- client
- package.json
- server
- package.json
- package.json
You should use the following command to install the dependencies in all folders:
npm i && npm i --prefix client && npm i --prefix server

How to install bower dependencies using npm install?

I want npm install to install the bower dependencies as well. I have a bower.json file containing frontend packages and there is package.json file which contains the backend packages. After i run npm install, node_modules are installed whereas the dependencies mentioned in bower.json file are not installed.
I don't want to use bower install rather I want to do all this with npm install command.
It's quite simple. If you have bower listed in package.json as dependency you may add postinstall script to your package.json as follows:
"scripts": {
"postinstall": "bower install"
}
and running npm install will launch also bower install automatically