Offline installation of npm packages
Overview
It’s been awhile since the last time I posted on my blog. I’ve been quite busy during the past weeks and kept resting on weekends. Sorry for not being able to post and give weekly updates. Today, I’ll tackle something about Node.js.
Node.js is rapidly gaining popularity in software development nowadays due to many reasons (may check the trend here). One of the reasons is the usage of JavaScript for server-side. Imagine, coding the back-end and front-end using the same language.
Also, it uses a package manager named, npm. It has a repository of JavaScript packages which are retrieved from the Internet to be used by Node.js applications.
Problem
Not all organizations provide complete access to the Internet. Some might have intranet networks without any access to the Internet. Given this scenario, how can an individual use npm to install desired Javascript libraries?
Solution
As the package manager of Node.js relies on an Internet connection to retrieve packages. npmbox is created in order to archive online packages including their dependencies. Yes, the dependencies are included. It can greatly save us from installation headaches.
Workstation with Internet connection:
- Download and install Node.js. (This will automatically install
npm
) - Open any desired terminal / command-line client.
-
Install the npmbox package from
npm
.npm install npmbox
-
To verify that npmbox is successfully installed, may execute the commands provided by npmbox like
npmbox
andnpmunbox
directly from the command-line.npmbox --help npmunbox --help
-
Now, we must archive the npmbox package in order to be used by other machines without Internet connection. (It is rather strange that we are archiving the archiver.)
npmbox npmbox
- Copy the installer of Node.js and the generated file of npmbox to the workstations without Internet connection.
Workstation without Internet connection:
- Install Node.js. (Using the downloaded file earlier)
- Open any desired terminal / command-line client.
- Go to the directory having the .npmbox file.
-
Untar the .npmbox file
tar -xvf yourfile.tar
- In the same directory, a new folder named
.npmbox-cache-folder
will be generated. -
Execute the following command in order to use the offline feature of npm for installing npmbox. (I got the command from here.)
npm install --global --cache ./.npmbox-cache --optional \ --cache-min 999999 --fetch-retries 0 \ --fetch-retry-factor 0 --fetch-retry-mintimeout 1 \ --fetch-retry-maxtimeout 2 npmbox
- Verify if npmbox is successfully installed to the machine.
- May now install archived JavaScript packages (in
.npmbox
extension) using thenpmunbox
command.
Notes:
- In case error is encountered while unboxing the archived package, may check if the npmbox installed in the workstations have the same versions.
- If the npmbox versions are the same, but online errors are still encountered, try installing version 1.0 of npmbox.
Leave a comment