nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.44k stars 276 forks source link

How to download the latest LTS from bash? #4386

Closed artfulrobot closed 1 month ago

artfulrobot commented 2 months ago

Details

For years I've been scraping nodejs.org/en, using a simple xpath '//a[contains(@title, "LTS")]/@data-version' to find the latest LTS version.

From there I could download and install it within my bash script.

Now the homepage has changed has removed any semantic data, so I can't find the latest LTS.

My script did this:

  1. checks currently installed version
  2. checks LTS latest version
  3. if 2>1 then it offers to download and install newer version.

Node.js version

Not applicable.

Example code

No response

Operating system

linux

Scope

Installation?

Module and version

Not applicable.

richardlau commented 2 months ago

Rather than scrape the website, you'd be better off parsing the data from either https://nodejs.org/download/release/index.json or https://nodejs.org/download/release/index.tab.

artfulrobot commented 2 months ago

@richardlau thanks for the links, this seems to work:

curl -s 'https://nodejs.org/download/release/index.json' | jq -c 'map(select(.lts)) []| {date, version}' | sort | tail -n1 | jq '.version'