HTTP redirecting service for fetching NodeJS installation package matching filter
Automatic installation of NodeJS always fails due to one of two reasons:
- On using some version manager such as n there are some pre-requisites to be met such as having a running NodeJS environment.
- Automatically getting URL of latest available release package matching your operating system isn't well supported by nodejs.org website.
Since I wanted to set up static NodeJS in a docker image without requiring to fetch all dependencies as declared by either distribution I've created this package providing HTTP service taking requests including some filter to be applied on choosing best matching NodeJS installation package and redirect to that one's download archive so fetching the right package is as simple as using
Well I might have been using nvm instead. But on my behalf, that perception was a little bit late. ;)
npm i -D latest-node
On Linux invoke with:
PORT=3000 npm start
On Windows try:
set PORT=3000 && npm start
The whole service makes sense when installed in a persistently available location, only. Thus you might want to expose it on a public server or on a server in your intranet. Instead of using browser use of
curl may be preferred for automatically downloading installation packages. For the sake of demonstration this documentation expects service to run on local host just like in case of starting it as given before.
Running Service With Docker
Docker images are built this way:
docker build https://github.com/cepharum/latest-node.git
The resulting docker image is exposing HTTP service on its port 3000.
Try fetching this URL in your browser:
This will display URL for downloading some package of latest stable release of NodeJS.
Now omit the
/test part of path and you will be redirected this time for actually downloading that package.
The service is responding to any incoming URL trying to parse segments of requested path as values used to filter selected NodeJS package. You can filter by
- channel or major version
31for current release of selected major version
ltsfor current LTS release,
stablefor current stable release,
latestfor current release of latest major version
- operating system
win32for MS Windows
darwinfor MacOS X
aixfor IBM AIX
sunosfor Sun Solaris
arm7for ARM v7
arm6for ARM v6
arm64for ARM 64-bit
s390xfor the according platform
- archive format
tar.gzfor GZipped tar archive
tar.xzfor the smaller XZipped tar archive
7zfor the 7Zip archive
pkgfor the accordingly formatted archive
As an example
will redirect to the current stable release for Windows 32-Bit including installer.
The service doesn't require all segments to obey some order, but due to processing segments from left to right lately processed values might replace previous ones of same category as listed before.
will fetch recent-most release of
latest channel which is highest major version currently available for download.
Some filter values have defaults:
- The channel defaults to
- The mode defaults to
fetch(as this is considered the opposite of
All other filters are unset, but may be set up to match some available value in HTTP header field
would fetch any version of current LTS release for the current client platform in case of it is derivable from user agent information or for any platform otherwise.
Using path segments for filtering is sufficient in most cases. But for the sake of higher flexibility it is possible to use query parameters for selecting filters, too. Query parameters address filters by name case-insensitively assigning value to be used. Multiple assignments to the same filter won't add up but every assignment replaces the previous one. Parameters are processed from left to right.
Support query parameter names are:
systemselect operating system filter
versionselect particular major version to use instead of some channel
channelselects particular channel to use instead of some particular major version
archiveselect desired format of archive
modeselects mode of operation (
The related values are equivalent to those listed before on processing path segments.
Example given before can be rewritten as
Both ways of providing filter definitions can be mixed with query parameters overriding path-based filters due to order of processing.