Chris Hager
Programming, Technology & More

How to install NodeJS 6.x Long-Term Support (LTS) on Ubuntu/Debian and CentOS

NodeJS 6.x is the current NodeJS long-term support (LTS) release, with NodeJS v6.9.4 being the most recent release as of time of writing. This guide shows a quick and reliable way to install the current NodeJS 6.x LTS version (including npm) on Ubuntu/Debian and CentOS.

console.log("Hello World");

We will use the system package manager (eg. apt or yum) to install NodeJS 6.x, to be able to continually receive security updates without risking a major version jump with possibly breaking changes.

You can jump directly to the installation instructions here:


About NodeJS Long-Term Support (LTS)

Every major version covered by the LTS plan will be actively maintained for a period of 18 months from the date it enters LTS coverage. Following those 18 months of active support, the major version will transition into “maintenance” mode for 12 additional months.

via https://github.com/nodejs/LTS#lts-schedule


NodeJS LTS Schedule

NodeJS 6 LTS will be actively maintained until April 2018, and passively maintained until April 2019, as shown in the image above. It is recommended to use the long-term support version for client projects, in order to be guaranteed a long active maintenance with security updates..


Installing NodeJS 6.x LTS on Ubuntu and Debian

This is the official way to install NodeJS 6.x on Ubuntu, Debian, Linux Mint, Linux Mint Debian Edition (LMDE) and elementaryOS:

# Install NodeJS 6.x repository
curl -sL https://deb.nodesource.com/setup_6.x | bash -

# Install NodeJS and npm
apt-get install -y nodejs

The setup_6.x bash script basically just checks whether your operating system version is suppored and adds the corresponding repository (eg. https://deb.nodesource.com/node_6.x xenial InRelease).


Installing NodeJS 6.x LTS on CentOS 7

NodeJS provides a script for CentOS/Fedora/RHEL based distributions, which checks your operating system and adds the corresponding RPM repository for yum, the standard package manager:

# Install NodeJS 6.x repository
curl -sL https://rpm.nodesource.com/setup_6.x | bash -

# Install NodeJS and npm
yum install nodejs

The content of the script can be found here: https://rpm.nodesource.com/setup_6.x.


For feedback, ideas and recommendations, contact me on Twitter.

See also:


Custom Errors in TypeScript 2.1

TypeScript 2.1 introduced a number of breaking changes, among them that “Extending built-ins like Error, Array, and Map may no longer work”.

For a subclass like the following:

class FooError extends Error {
    constructor(m: string) {
        super(m);
    }
    sayHello() {
        return "hello " + this.message;
    }
}
  • methods may be undefined on objects returned by constructing these subclasses, so calling sayHello will result in an error.
  • instanceof will be broken between instances of the subclass and their instances, so (new FooError()) instanceof FooError will return false.

The suggested solution of manually adjusting the prototype with Object.setPrototypeOf(this, FooError.prototype) might not work due to Object.setPrototypeOf(..) being missing.

The Solution

After trying several approaches, the solution presented here seems to be the way which reliably works, including with promises (native and bluebird):

import * as util from "util";

// Custom Error 1
const CustomError1 = function(message) {
    Error.captureStackTrace(this, this.constructor);
    this.name = this.constructor.name;
    this.message = message;
};
util.inherits(CustomError1, Error);

// Custom Error 2
const CustomError2 = function(message) {
    Error.captureStackTrace(this, this.constructor);
    this.name = this.constructor.name;
    this.message = message;
};
util.inherits(CustomError2, Error);

// Tests
let e = new CustomError1("Foo");
console.log("instanceof error: ", e instanceof Error);  // true
console.log("instanceof own class: ", e instanceof CustomError1);  // true
console.log("instanceof other error class: ", e instanceof CustomError2);  // false

If you have suggestions or feedback, let me know via @metachris.


Great Talks and Presentations at 33C3

The Chaos Computer Congress is Europe’s leading hacker and tech community conference, taking place annualy in Hamburg, Germany between Christmas and New Year. This year was the 33rd time (hence 33C3), and as usual featured a large number of amazing talks and presentations.

My personal favorites

Topics


Tech

Embedded / IoT

Dieselgate

Gaming

Surveillance

Space

Hacking, Security & Exploits

Politics, Society & World

Lightning Talks


Discuss this post on Hacker News.

Blog Archive
swirl