latest-node v0.0.3
latest-node
HTTP redirecting service for fetching NodeJS installation package matching filter
About
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 curl.
Well I might have been using nvm instead. But on my behalf, that perception was a little bit late. ;)
Installation
npm i -D latest-nodeRunning Service
On Linux invoke with:
PORT=3000 npm startOn Windows try:
set PORT=3000 && npm startThe 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.gitThe resulting docker image is exposing HTTP service on its port 3000.
Using Service
Try fetching this URL in your browser:
http://127.0.0.1:3000/test/stableThis 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.
http://127.0.0.1:3000/stableURL Format
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
4...31for current release of selected major versionltsfor current LTS release,stablefor current stable release,latestfor current release of latest major version
- operating system
ms,win,windowsorwin32for MS Windowslinuxorgnufor GNU/Linuxmacos,macosxordarwinfor MacOS Xaixfor IBM AIXsolaris,sunorsunosfor Sun Solaris
- platform
64,x64oramd64for x6432orx86for x86arm,armv7orarm7for ARM v7armv6orarm6for ARM v6arm64for ARM 64-bitppc64,ppc64leors390xfor the according platform
- archive format
tar,gzortar.gzfor GZipped tar archivexzortar.xzfor the smaller XZipped tar archive7zipor7zfor the 7Zip archivezip,msiorpkgfor the accordingly formatted archive
As an example
http://127.0.0.1:3000/stable/win/32/msiwill 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.
http://127.0.0.1:3000/stable/latestwill 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
lts. - The mode defaults to
fetch(as this is considered the opposite oftestshown before).
All other filters are unset, but may be set up to match some available value in HTTP header field User-Agent. So
http://127.0.0.1:3000/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.
Query Parameters
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:
os,operatingsystemorsystemselect operating system filterplatform,cpuorprocessorselect platformmajororversionselect particular major version to use instead of some channelchannelselects particular channel to use instead of some particular major versionformatorarchiveselect desired format of archivemodeselects mode of operation (testorfetch)
The related values are equivalent to those listed before on processing path segments.
Example given before can be rewritten as
http://127.0.0.1:3000?channel=stable&os=win&cpu=32&format=msiBoth ways of providing filter definitions can be mixed with query parameters overriding path-based filters due to order of processing.