4 # homepage: https://nodejs.org
5 # tagline: JavaScript V8 runtime
7 # Node.jsĀ® is a JavaScript runtime built on Chrome's V8 JavaScript engine
13 # node -e 'console.log("Hello, World!")'
17 # ### A Simple Web Server
22 # var http = require('http');
23 # var app = function (req, res) {
24 # res.end('Hello, World!');
26 # http.createServer(app).listen(8080, function () {
27 # console.info('Listening on', this.address());
41 # npm install --save express
49 # var express = require('express');
50 # var app = express();
52 # app.use('/', function (req, res, next) {
53 # res.end("Hello, World!");
56 # module.exports = app;</code></pre>
64 # var http = require('http');
65 # var app = require('./app.js');
67 # http.createServer(app).listen(8080, function () {
68 # console.info('Listening on', this.address());
84 new_node_home="${HOME}/.local/opt/node-v${WEBI_VERSION}"
85 new_node="${HOME}/.local/opt/node-v${WEBI_VERSION}/bin/node"
87 # Test for existing version
89 cur_node="$(command -v node)"
91 if [ -e "$new_node_home/bin/node" ]; then
92 # node of some version is already installed
93 if [ "v${WEBI_VERSION}" == "$("$new_node_home/bin/node" -v 2>/dev/null)" ]; then
94 echo node v${WEBI_VERSION} already installed at $new_node_home
98 if [ -n "$cur_node" ] && [ "$cur_node" != "$new_node" ]; then
99 echo "WARN: possible conflict with node v$WEBI_VERSION at $cur_node"
102 # Note: this file is `source`d by the true installer and hence will have the webi functions
104 # because we created releases.js we can use webi_download()
105 # downloads node to ~/Downloads
108 # because this is tar or zip, we can webi_extract()
109 # extracts to the WEBI_TMP directory, raw (no --strip-prefix)
112 pushd "$WEBI_TMP" 2>&1 >/dev/null
113 echo Installing node v${WEBI_VERSION} as "$new_node"
115 # simpler for single-binary commands
116 #mv ./example*/bin/example "$HOME/.local/bin"
118 # best for packages and toolchains
119 rm -rf "$new_node_home"
120 if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then
121 rsync -Krl ./node*/ "$new_node_home/" 2>/dev/null
123 cp -Hr ./node*/* "$new_node_home/" 2>/dev/null
124 cp -Hr ./node*/.* "$new_node_home/" 2>/dev/null
133 # TODO get better output from pathman / output the path to add as return to webi bootstrap
134 webi_path_add "$new_node_home/bin"
136 echo "Installed 'node' and 'npm'"