Is it possible to move Nodejs modules to be used offline?

Asked

Viewed 1,621 times

4

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

I tried to copy the directory node_modules but it doesn’t work, there is some way to use the modules without having to download them?

  • Can you name which modules you are using and which computer operating systems your work and your home? I suspect that some module of yours is compiled and are different Oss, or else you are doing something wrong

  • SO is the same, Windows 7, but for example when I run grunt test no prompt is informed that grunt não existe ou n é um comando interno..

  • vc deu npm install -g Grunt-cli?

  • if I run this command will be downloaded from the network, and my network access is limited, returning a proxy error

3 answers

2

In the browser there is still no way for you to use the function require on Ode, so this is very important for understanding this issue. The staff of Commonjs documented some possible ways to work with modules and packages in Javascript, W3C is working with Htmlimports and a package system.

Faced with this information, you can in some hybrid packages make symbolic link or move to a folder and click on your browser using the command <script> 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 It is a very promising project similar to NPM, but focused on packages for browsers, today it is also widely used by people who use Gruntjs, allows the installation of NPM packages, direct from github and even compressed files.

And the Grunt-Bower can help you to work with both.

  • I already use the bower, and did not know the browsify, thanks for the reply!

1


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

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

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

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

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

Folder of your project type:

./node_modules/grunt-cli/bin/grunt

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

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

0

In case anyone is interested, I found a great and simple solution, is the npmbox, that allows you to create a custom package with all dependencies.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.