Is it possible to move NodeJS modules to be used 'offline'?

4

I use GruntJS for personal projects, I would like to use the benefits of this tool at work, however the use of the network is limited and I can not install via the prompt.

I tried to copy the node_modules directory but it does not work, is there any way to use the modules without having to download them?

    
asked by anonymous 09.02.2014 / 23:32

3 answers

1

Reading the comments, I understood something else, that the user would install node packets offline and not use them in the browser. As the previous answer proves useful to other users I will not delete it.

There is a folder of the node (which in windows I do not know where it is, but probably where you installed nodejs) where all the node_modules that you install with the command -g , and a folder of binaries /bin where it places the identified binaries in the package.json , in windows the node adds in the PATH (system variable) this folder, then the executables are found in the console. You can do this manually if you can not use npm install .

In linux, they usually stay in: /usr/local/lib/node_modules/ And the binaries it does symbolic link in: /usr/local/bin/ Note: The folder may vary from distro to distro.

How to change the windows PATH? (open topic to help you by not polluting your question and not by placing external link)

The other way is for you to execute the binaries directly from the folder, they will also work, let's assume you are in the folder of your project and want to run grunt .

Your project folder type:

./node_modules/grunt-cli/bin/grunt

I recommend using a windows power-shell to work with NPM and not the prompt, because you will have a more elegant environment.

Finally, do not forget that where you are copying your ./node_modules/ if it was installed with -g will not be in the project folder but in the installation folder of nodejs, so to use and copy all of it project install all dependencies without the -g , to be able to use relative path as of the example.

    
10.02.2014 / 13:25
2

In the browser there is still no way for you to use the require function on the node, so this is very important to understanding this question. The staff at CommonJS documented some possible ways to work with modules and packages in Javascript, W3C is working with HTMLImports and a packages.

In front of this information, you can in some hybrid packages make a symbolic link or move to a folder and load into your browser using the <script> command as long as the files are in a web accessible location on your server.

There are 2 interesting projects that can also help you:

  • Browsify Allows you to load node modules in your browser.
  • Bower This is a very promising project similar to NPM, but focused on packages for browsers, today is also widely used by people which uses GruntJS, allows the installation of NPM packages, direct from github and even compressed files.

And grunt-bower can help you work with both.

    
10.02.2014 / 00:14
0

If anyone has an interest, I've found a great and simple solution, it's npmbox , which allows you to create a custom package with all the dependencies.

    
14.03.2014 / 02:45