Installing Node packages globally without internet connection - node.js

I am working on Windows Server 2012 R2, but external internet connection is restricted in my Org. So i can not install any NPM packages on server directly.
I want to install pm2 OR forever packages globally so that all the user profiles(admin and users) can access that from any directory.
Please guide me in this case.

From another pc with internet connection, you can download the source code from github. For example, for pm2 it is : https://github.com/Unitech/pm2
After downloading the source code, you need to look into the package.json file and download all the dependency source code too. ( One easy way to do all of above is to use npm to fetch pm2 in a local directory then copy the pm2 along with all dependencies to a USB)
Transfer files into a directory of your server workstation using USB or any other suitable means.
Add the pm2/bin directory to your PATH.
Test with pm2 -v from command line to ensure PATH addition is correct.

Related

nodejs - install production build of reactjs app on offline server, then set up to run as a service

I installed the following package globally using
npm install -g serve
on my development PC which has internet. It is currently the only package installed globally on my PC.
https://github.com/vercel/serve#readme
After I compile and create a build folder, i run the following command to have the production version of code run using HTTPS.
serve -s build --listen 3000 --ssl-cert "/my/cert/server.crt" --ssl-key "/my/key/server.key"
Ok, so here comes the problem. I have to run my code on a server that is not connected to the internet. I've copied and moved the global node_modules folder over to the server and confirmed the permissions are the same between the server and dev pc. I also confirmed that the package is seen as installed on the server by:
npm list -g --depth=0
When I run the serve command above on the server, it has no clue what serve is. CentOS complains about
bash: serve not found...
So, I added an alias to the ./~bashrc file on the server (which I also had to do on my dev pc and reloaded:
vim ~/.bashrc
export PATH="$(npm bin -g):$PATH"
source ~/.bashrc
I found the export command in another SO post, and it worked on my dev pc, however linux still does not recognize the serve command. I also need to know how to determine how to run this command from within a service, which means I also need the absolute path of the "serve" command.
I'm kinda stuck on this, since all the articles online only talk about how to run "npm start" as a service, which I can do for a development build of software with no issues. I cannot find anything on how to set up a service for a production build.
I dont 100% need to use serve, but my other coworker is using it for his project, which has internet access.
I've even gone as far as trying to piece together the location of the main js file in the module:
/path/to/node_modules/serve/build/main.js -s build --listen 3000 --ssl-cert "/my/cert/server.crt" --ssl-key "/my/key/server.key"
This will allow me to start the service, but then I get all kinds of cross site scripting errors from my apache backend server.
Any help would, as always, be appreciated! Thanks!
Disregard,
When I ran npm install -g serve on the pc with internet, it created a soft link to the serve module. I discovered this by running the following on my dev pc:
which serve
I created that soft link on the offline server, and it appears to be working.

Into which folder does npm install installs

I installed an application via npm install and I can open the application in my webbrowser via http://localhost:3000/without any problem. What folder do I have to open to see what is displayed when I open the URL http://localhost:3000/ in my webbrowser?
by default npm install will install packages into node_modules which resides in your project root where package.json is located.
It seems you have a script which will spin up a webserver, in most cases it will not expose the node_modules directory on that webserver (for good reason).
The point is that you should be including the packages you installed within the script you use for your application that is served.
edit: you can read up on how to use nodejs packages here: https://docs.npmjs.com/using-npm-packages-in-your-projects

npm install package from local folder

I am behind a firewall and I believe git connection at 9418 are getting blocked. So I want to install a repository via npm (mysam https://github.com/mysamai/mysam). I tried installing directly with
npm --proxy <proxy-details> install -g mysam
Which fails saying -
fatal: Unable to look up github.com (port 9418) (No such host is known. )
So to avoid that I downloaded zip of the git repository and found on internet to use
cd package-folder
npm link
However that also fails stating same error. Is there any option to install the locally downloaded repository.
Thanks
Using npm without an internet connection just does not work.
This is how we worked around this for a fully isolated node project:
You need a machine with internect connection. On this machine you do all the npm install calls.
Getting the installed files to other machines is easy if you are on linux or mac. With windows you are likely to have problems with long path names. Windows can handle them internally but almos all tools including windows explorer, winzip, 7-zip and friends cannot handle them. You have to use either robocopy or put everything into a git repo to move them arround. For GIT check https://stackoverflow.com/a/26111092/671639 to make it handle long path names on Windows. Also add the node_modles/**/bin/** folder to .gitignore.
We used GIT and moved around the repo. Attaching it as a remote allows to pull in new installed modules to the closed system.
Once the new module is available in your closed system call npm rebuild to make sure you have all the tooling availbable.
Of course this means to add node_modules to GIT or whatever SCM you are using.

how to install forever node module globally on windows machine?

I am trying to install node module "forever" globally on windows machine. So tried installing it with "-g" switch
C:\npm install -g forever
I specifically interested in file "forever.cmd". However this file gets install into the folder
C:\Users\myusername\AppData\Roaming\npm
Well this is not truly global folder. Other users of the same machine cannot access this. Is there any other location forever module gets installed?
I don't think there's a perfect solution for this issue. You could re-install NodeJS, which includes NPM, but install it to a global folder like your system folder (installation instructions here). However, this will require administrator access which will make it potentially unsafe and a pain to use.
I would suggest just making a shortcut, alias, or adding the path to the environment variables for the user in question. That way when you do "forever start" in one user account you can do "forever list" in a different user account.
Good luck.

Installing npm modules in a VM shared directory and grunt issues

I'm trying to put together a development environment and npm is causing me problems. Here is my scenario:
I have a development machine running Windows and VMWare Player. I have a Ubuntu Server VM (no UI) which is configured with Apache, PHP, NodeJS etc. As the VM has no UI I want to use the host OS for development. I set up a shared directory which in the VM is accessed as /mnt/hgfs/source/<project name>.
The problem comes when I attempt to run npm install within this directory. I see a lot of errors like Error: UNKNOWN, symlink '../requirejs/bin/r.js'. I know that my package.json file is OK because if I copy all files out of the share and into a regular unix directory (/var/www/<project name>) npm install works fine. So npm has a problem installing modules in the shared directory.
I thought I could get around this by installing the node packages globally but, for whatever reason, the GruntJS enthusiasts don't like that and it must be present locally. I then tried to create an npm link from global to local but that just results in a new error: Error: May not delete: /usr/lib/node_modules/grunt. I have full permissions on the /usr/lib/node_modules directory and all sub-directories.
I really don't want to write the entire project using a command-line text editor in the VM but it looks like I cannot have my code-base in a directory available to both the host and guest OS through VMWare.
I would very much appreciate any suggestions on how to either 1) allow npm modules to be installed in my shared directory, 2) run Grunt globally, or 3) solve the npm link error I'm seeing.
EDIT: Shortly after posting this I realised the fundamental issue here - it's not possible to create symbolic links within a VM shared directory when the host OS is Windows. As npm install uses symlinks by default it didn't work, and this is why the accepted solution does work.
Try the following:
npm install --no-bin-links
Grunt should be local since the plugins and gruntfile.js may require a certain version of Grunt in order to run your tasks. If another developer would like to run your tasks, they could just issue an npm install and they are set. (See this for more info.) grunt-cli is global which is used to run the local version of grunt

Resources