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!")'
19 # ### A Simple Web Server
24 # var http = require('http');
25 # var app = function (req, res) {
26 # res.end('Hello, World!');
28 # http.createServer(app).listen(8080, function () {
29 # console.info('Listening on', this.address());
45 # npm install --save express
55 # var express = require('express');
56 # var app = express();
58 # app.use('/', function (req, res, next) {
59 # res.end("Hello, World!");
62 # module.exports = app;</code></pre>
72 # var http = require('http');
73 # var app = require('./app.js');
75 # http.createServer(app).listen(8080, function () {
76 # console.info('Listening on', this.address());
94 common_node_home="${HOME}/.local/opt/node"
95 new_node_home="${HOME}/.local/opt/node-v${WEBI_VERSION}"
96 new_node="${HOME}/.local/opt/node-v${WEBI_VERSION}/bin/node"
99 rm -rf "$common_node_home"
100 ln -s "$new_node_home" "$common_node_home"
102 # TODO get better output from pathman / output the path to add as return to webi bootstrap
103 webi_path_add "$common_node_home/bin"
106 if [ -x "$new_node" ]; then
108 echo "switched to node v${WEBI_VERSION} at $new_node_home"
112 # Test for existing version
114 cur_node="$(command -v node)"
117 if [ -n "$cur_node" ]; then
118 cur_node_version="$("$cur_node" -v 2>/dev/null)"
119 if [ "$cur_node_version" == "v${WEBI_VERSION}" ]; then
120 echo "node v${WEBI_VERSION} already installed at $cur_node"
123 if [ "$cur_node" != "$common_node_home/bin/node" ]; then
124 echo "WARN: possible conflict between node v${WEBI_VERSION} and ${cur_node_version} at ${cur_node}"
126 if [ -x "$new_node" ]; then
128 echo "switched to node v${WEBI_VERSION} at $new_node_home"
135 # Note: this file is `source`d by the true installer and hence will have the webi functions
137 # because we created releases.js we can use webi_download()
138 # downloads node to ~/Downloads
141 # because this is tar or zip, we can webi_extract()
142 # extracts to the WEBI_TMP directory, raw (no --strip-prefix)
145 pushd "$WEBI_TMP" 2>&1 >/dev/null
146 echo Installing node v${WEBI_VERSION} as "$new_node"
148 # simpler for single-binary commands
149 #mv ./example*/bin/example "$HOME/.local/bin"
151 # best for packages and toolchains
152 rm -rf "$new_node_home"
153 if [ -n "$(command -v rsync 2>/dev/null | grep rsync)" ]; then
154 rsync -Krl ./node*/ "$new_node_home/" 2>/dev/null
156 cp -Hr ./node*/* "$new_node_home/" 2>/dev/null
157 cp -Hr ./node*/.* "$new_node_home/" 2>/dev/null
168 echo "Installed 'node' and 'npm'"