install nodejs | zuhdi.org

Install Node.js /archive

Environment

  • Debian 9.7 x64
  • nvm 0.34.0
  • npm 6.9.0
  • node 12.2.0

Excerpt

Log 2019 / 05

1. Install nvm

root@athos:~# apt-get update && apt-get -y upgrade && apt-get -y dist-upgrade

wget -qO- \
  https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

root@athos:~# wget -qO- \
>   https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
=> Downloading nvm as script to '/root/.nvm'

=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  
# This loads nvm bash_completion

root@athos:~# source ~/.bashrc

root@athos:~# nvm --version
0.34.0

2. Install node

root@athos:~# nvm ls-remote | tail -3
       v10.10.0
       v10.11.0
       v10.12.0

root@athos:~# nvm install 12.2.0
Downloading and installing node v12.2.0...
Downloading https://nodejs.org/dist/v12.2.0/node-v12.2.0-linux-x64.tar.gz...
--2019-05-12 07:07:04--  https://nodejs.org/dist/v12.2.0/node-v12.2.0-linux-x64.tar.gz
Resolving nodejs.org (nodejs.org)... 104.20.23.46, 104.20.22.46, ...
Connecting to nodejs.org (nodejs.org)|104.20.23.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 21053621 (20M) [application/gzip]
Saving to: ‘/root/.nvm/.cache/bin/node-v12.2.0-linux-x64/node-v12.2.0-linux-x64.tar.gz’

/root/.nvm/.cache/bin/node-v12.2 100%[===================>]  20.08M  5.13MB/s in 3.9s

2019-05-12 07:07:10 (5.13 MB/s) - '/root/.nvm/.cache/bin/
node-v12.2.0-linux-x64/node-v12.2.0-linux-x64.tar.gz' saved [21053621/21053621]

Computing checksum with sha256sum
Checksums matched!
Now using node v12.2.0 (npm v6.9.0)
Creating default alias: default -> 12.2.0 (-> v12.2.0)

root@athos:~# node --version
v12.2.0

root@athos:~# npm version
{
  npm: '6.9.0',
  ares: '1.15.0',
  brotli: '1.0.7',
  cldr: '35.1',
  http_parser: '2.8.0',
  icu: '64.2',
  llhttp: '1.1.3',
  modules: '72',
  napi: '4',
  nghttp2: '1.38.0',
  node: '12.2.0',
  openssl: '1.1.1b',
  tz: '2019a',
  unicode: '12.1',
  uv: '1.28.0',
  v8: '7.4.288.21-node.17',
  zlib: '1.2.11'
}

3. Hello, World!

cat <<EOF > example.js
const http = require('http');

const hostname = '0.0.0.0';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, World!\n');
});

server.listen(port, hostname, () => {
  console.log(\`Server running at http://\${hostname}:\${port}/\`);
});
EOF

root@athos:~# cat <<EOF > example.js
> const http = require('http');
>
> const hostname = '0.0.0.0';
> const port = 3000;
>
> const server = http.createServer((req, res) => {
>   res.statusCode = 200;
>   res.setHeader('Content-Type', 'text/plain');
>   res.end('Hello, World!\n');
> });
>
> server.listen(port, hostname, () => {
>   console.log(\`Server running at http://\${hostname}:\${port}/\`);
> });
> EOF

root@athos:~# node example.js
Server running at http://0.0.0.0:3000/

Hugo. Malte Kiefer & Zuhdi Najib.