How to make a package.json from hacked node_modules folder - json

So I installed some modules with npm and others I just copied and pasted into the node_modules folder. One module I had to hack.
Now when I perform npm install for a new module, it deletes some of the modules and overwrites the hacked one to its original state.
It feels like I didn't run npm init early enough in development to properly set my package.json file from the start and now when I do run npm init it only picks up some of the modules.
How can I get everything synced up again? Is there a way to take a node_modules folder and get npm to become familiar with all the modules again? Also, is there any way to prevent the hacked one from going back to its original state?
Thank you!

Here's an answer to a similar question
You can fork the repo of the "hacked" module and include the forked repo in your package.json file. As for the "copied" modules, you can either copy them outside your node_modules folder and import using relative paths, or install it as a local npm package.

Related

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

Can I install just Gulp globally?

I'm constantly working on new web development projects that don't ever, in practice, need their node_modules folder when deploying. It would suit me much more if I was just able to create a small gulpfile.js for each project, rather than 6000+ files contained in the node_modules folder for every project, that are only ever used by me on this machine.
I only use Gulp to compile SASS and prefix and minify my CSS. I don't need to worry about any other type of deployment issues, but the documentation says I need both: Global and local copies of Gulp.
Gulp needs to be installed locally, but you can link the local install to a global install:
npm install --global gulp
npm link gulp
See also https://stackoverflow.com/a/30742196/451480

How to install grunt file for bootstrap

I need to install bootstrap. So far I have done step 1 succesfully. I was able to install the grunt file but step two is giving me problems for days, and I do not want to spend a next day on it.
step 1: Install grunt-cli globally with npm install -g grunt-cli
step 2: Navigate to the root /bootstrap/ directory, then run npm install. npm will look at the package.json file and automatically install the necessary local dependencies listed there.
Whenever I do npm install, I get npm can't find a package.json file in your current directory. Well I do not know how to get it to my current directory, at the comand prompt it is C:\Users\Crisp>. the bootstrap file is in this directory C:\Users\Crisp\bower_components\bootstrap. There you will see the package.json file.
I really do not know what to do! I have searched on this site for supposed answers but no one says how to change the directory or actually get it to work. There is nowhere I see how to change a directory or root director but everyone keeps saying change root directory I am not a tech man, I do not know. PLEASE I NEED HELP!
I think what you are looking for if you are following instructions in this link (http://getbootstrap.com/getting-started/) you can go to the root directory by command line:
cd bower_components
then
cd bootstrap
just in case, to determine your current directory just type pwd
good luck
#contactmzn

tell npm install to get rid of no longer needed dependencies

I added a couple of libraries to my package.json file, but now I found out I no longer need them
Is there some command line parameter to pass to npm install to tell it to remove no longer needed packages? that is, those packages in node_modules that are no longer in package.json
Or shall I just remove the node_modules folder and run npm install once again... (I was hoping for a smarter solution)
--
I found out that npm ls correctly recognizes no longer needed libraries as extraneous
You can do npm prune to remove extraneous packages. Link to docs.

Files to commit to repository in a Yeoman project

when you generate a yeoman project, do you commit the node_modules that is generated into your code repository?
It seems like it is necessary for another developer to check out a project and develop from it, but it seems like a lot of files to commit which seem unrelated to a project itself.
You can just run npm install to get the dependencies installed. However there are multiple benefits to committing your dependencies, which you can read about in this blog post:
Checking in front-end dependencies (for Bower, but applies to npm too)