npm recursive install bower dependencies - json

I have multiple node modules developed by myself stored on a private gitlab server. In my Project, i install those modules with bower, so my Project structure Looks like this:
appname
bower_components
module1
...
package.json
module2
...
node_modules
...
package.json
When i call npm install only the dependencies from the package.json file located in the Folder "appname" will be installed. The Problem is, that my modules, which i install with bower, also have dependencies, which are not listed in the package.json in the root Folder. How can i install those dependencies without installing them globally? It should by something like npm install bower_components\module1. I also tried to use the command line Option --prefix but it only copies the Folder inside the node_modules Folder.
Thanks for your help

Related

Does Webpack install -g, automatically install to nodeJS's package.json? Or is this only for local installs?

Does Webpack install -g, automatically install to nodeJS's package.json? Or is this only for local installs?
So I'm tired of trying to find workarounds for require() is not defined. Meaning I would need a module loader for my project to include modules client side. Well, I've downloaded the famous 'webpack' module loader, globally
npm install -g webpack
and I noticed it didn't install to "devDependencies" in my package.json file. But I also install webpack-dev-server, but locally,
npm install webpack-dev-server --save-dev
and it was saved into my package.json. Was this saved because I used --save-dev or because I installed locally?
I'm getting an error stating my webpack module I downloaded doesn't have a configuration file, so I'm assuming I install webpack wrong, and maybe it shouldn't have been installed globally. Please help with the understanding of globally and locally, as well as why this -g webpack install didnt get saved to the package.json?
The command npm install --gloabl will install a package in global scope and make it's bin command available to you globally. This has nothing to do with the folder or project your are in right now. That means a global install will not leave anything in any package.json files.
Learn more about npm install: https://docs.npmjs.com/cli/install
npm install -g webpack will save your files in your OS file system.
npm install webpack-dev-server --save-dev will save your package in your project directory inside a folder called node_modules.
The later one will make an entry in package.json file so that next time you can install all dependdencies with just npm install command. This command installs all your packages listed in package.json.
Missing Config file: Its looking for a file called webpack.config.js. More info can be found here: https://webpack.js.org/configuration/

Create/update package.json for existing project

I have a NodeJS project that was started long ago. It has many packages that were installed before I understood the --save flag. A few versions ago npm decided that it would delete packages that are not mentioned in package.json (an insane thing to do). This causes a terrible problem.
Now I understand --save and use it properly. However, I cannot figure out a way to update package.json with packages that are not listed.
Is there some way to cause npm or some other program to look at a project and add missing dependencies? I'd be happy enough if it completely recreated the dependency structure.
Suggestions?
UPDATE : npm 3.5+
Remove everything from package.json and run: npm init --yes.
This will recreate the package.json with dependencies, but not the devdependencies.
npm 3
If your're on Unix based systems, from inside your project root folder, with a package.json file already created (npm init, as you mentioned), run:
npm install $(ls node_modules/) --save
and it will reinstall the packages, and save them into package.json as dependencies

grunt - config object

This sample grunt file https://gruntjs.com/sample-gruntfile reads in a config object from package.json and stores it in the pkg property:
pkg: grunt.file.readJSON('package.json')
However, the page doesn't give a sample package.json file. Later on it refers to pkg.name. I assume this is a top level key in package.json. E.g.
{
"name": "this value here",
}
Is that correct?
Yes that's correct.
The package.json file is the heart of npm which is used by grunt.
You can generate one for your project using npm initand filling out the options or you can manually create and update it.
It gets updated automatically when using the --save option when adding modules to grunt.
npm install grunt-contrib-copy --save
This will install the module to your node_modules folder and update the dependencies section in your package.json
You only need to save the package.json file in your repo and each developer can download all dependencies listed in your package.json by calling npm install

How i can dynamically generate bower_components with bower.json using gulp

I want to install dependencies listed in bower.json or package.json using gulp .
NOTE : I have deleted bower_components folder and I want when i run gulp task to install bower.json dependencies . How I can achieve that?
You can you this gulp module : https://www.npmjs.com/package/gulp-bower
It allows you execute bower commands such as install and update.

gulp permission and local install without the json file

As it says on the gulp io to install gulp globally you need to run
npm i -g gulp
which will return an EACCES error so you will use sudo in front of the command. Now I go into my new project directory that I want to install gulp in. As they say on the page to install it into your project folder you can use this command
npm i --save-dev gulp
if I do so it returns an EACCES error, which means I will need to use sudo again which I cannot quite get as I only want to install it in a local directory. If I do so it installs node_modules folder with path
gulp#3.9.0 ../../node_modules/gulp
Which means it is installed in my root directory and not the directory I wanted it to install it in. To fix it I can run
npm init
saying yes to everything and then
sudo npm install --save-dev gulp
Which will put node_modules into my project folder
My question is what prevents gulp installation into my project folder be as simple as it is in the gulp instruction? And what can I do to prevent this from happening in the future? I have researched this and people seem to get gulp running without the package.json file which is not a big deal but one more step if you want to jump start on something.