3

Question:

How to install NodeJS package (like grunt-cli) manually without using npm?

Environment:

  • I have installed Windows 10 with "Bash on Ubuntu on Windows".
  • I have successfully installed NodeJS + Grunt in the "normal" Windows environment without Bash.
  • NodeJS is installed in the bash environment (Linux-subsystem)
  • Grunt is not yet installed in the (Linux-subsystem)

Background (why):

My colleague's grunt tasks was developed for an Ubuntu environment and calls bash commands directly which obviously does not work in a "normal" Windows environment. This is an experiment to see if it is possible to run his grunt tasks in "Bash on Ubuntu on Windows" however, I am stuck on the part where npm tries to download the packages (network libraries are not yet supported by Linux-subsystem so commands like curl does not work).

I am hoping to "skip" the download part of npm by manually copying the downloaded version from the Windows environment (or GitHub) into the "node_modules" directory in the Linux-subsystem.

However, I do not know how to configure npm that there was a new package added and that it may use that package now.

Jasper Citi
  • 1,673
  • 1
  • 23
  • 31
  • 1
    I found another solution to my problem by editing /usr/lib/node_modules/npm/node_modules/npmconf/config-defs.js and replace all the lines that calls os.networkInterfaces() with a hard-coded object (copied from the native Windows' Nodejs version). Now npm seems to behave as expected. – Jasper Citi Sep 07 '16 at 07:59

3 Answers3

3

You can copy all the packages you need with dependencies into node_modules directory and it will work fine.

I think the best way is install packages using npm on a "normal" computer. Then copy the node_modules directory on "normal" computer to your target directory.

Yoshi
  • 563
  • 1
  • 6
  • 17
  • Yes, that is what I also thought but it turns out that one [cannot simply use Windows Explorer to copy the files](http://superuser.com/questions/1083962/windows-linux-subsystem-accessing-files-outside-of-ubuntu). So I copied the files the "Linux"-way and now node can access these files. My next problem is to get grunt to be executable. I found the grunt bin-script on Github, but I have no idea where to put it in Linux's file system. – Jasper Citi Sep 06 '16 at 11:51
  • You can install grunt-cli locally(using "npm install grunt-cli --save-dev"). Then you can execute it using "./node_modules/.bin/grunt" at the root directory of your project. – Yoshi Sep 07 '16 at 05:05
  • I found another solution. See my comment below my question, but I will accept your answer as it answers my original question. – Jasper Citi Sep 07 '16 at 07:59
0

Pre-built installer is now available in all platforms in the official website

https://nodejs.org/en/download/

cegprakash
  • 2,937
  • 33
  • 60
0

You no need to install modules when node_module dir is available. If project is cloned from version control (GIT) Repository or node_modules folder is not available you should run below command

npm install

Otherwise you need to insert node_modules manually to your project. you can also download node_modules from other computer and copy modules to your project

npm install --save <PACKAGE NAME>

Then you can find you dependency modules in your console folder.copy those files to your folder.