# tagline: JavaScript V8 runtime
# description: |
# Node.jsĀ® is a JavaScript runtime built on Chrome's V8 JavaScript engine
+# examples: |
+# ```bash
+# node -e 'console.log("Hello, World!")'
+# > Hello, World!
+# ```
+# <br/>
+# <br/>
+#
+# <table>
+# <tr>
+# <td>Run a webserver</td>
+# <td><pre><code class="language-bash">
+# mkdir my-server
+# pushd my-server
+# npm init
+# npm install --save express</code></pre>
+# <br/>
+# <code>app.js:</code>
+# <br/>
+# <pre><code class="language-javascript">'use strict'
+# var express = require('express');
+# var app = express();
+#
+# app.use('/', function (req, res, next) {
+# res.end("Hello, World!");
+# });
+#
+# module.exports = app;</code></pre>
+# <br/>
+# <code>server.js:</code>
+# <br/>
+# <pre><code class="language-javascript">'use strict'
+# var http = require('http');
+# var app = require('./app.js');
+# http.createServer(app).listen(8080, function () {
+# console.log('Listening on', this.address());
+# });</code></pre>
+# <br/>
+# <pre><code class="language-bash">npm start</code></pre>
+# </td>
+# </tr>
+# </table>
set -e
set -u
rm -rf "${NODEJS_UNTAR}"
chown -R $(whoami) "$node_install_path/lib/node_modules/" 2>/dev/null || $sudo_cmd chown -R $(whoami) "$node_install_path/lib/node_modules/"
-chown $(whoami) ""$node_install_path"/bin/" 2>/dev/null || $sudo_cmd chown $(whoami) ""$node_install_path"/bin/"
+chown $(whoami) "$node_install_path"/bin/ 2>/dev/null || $sudo_cmd chown $(whoami) "$node_install_path"/bin/
mkdir -p $node_install_path/lib/node_modules 2> /dev/null || $sudo_cmd mkdir -p $node_install_path/lib/node_modules
chown -R $(whoami) $node_install_path/lib/node_modules 2> /dev/null || $sudo_cmd chown -R $(whoami) $node_install_path/lib/node_modules
+# By default, npm is stupid and uses any version of node in any path. Stop that.
+# npm config set scripts-prepend-node-path true
+"$node_install_path"/bin/node "$node_install_path"/bin/npm --scripts-prepend-node-path=true config set scripts-prepend-node-path true
+
#######
# END #
#######