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());
82 pkg_get_current_version() {
83 # 'node --version' has output in this format:
85 # This trims it down to just the version number:
87 echo "$(node --version 2>/dev/null | head -n 1 | cut -d' ' -f1 | sed 's:^v::')"
90 pkg_format_cmd_version() {
91 # 'node v12.8.0' is the canonical version format for node
93 echo "$pkg_cmd_name v$my_version"
96 pkg_link_new_version() {
97 # 'pkg_common_opt' will default to $HOME/.local/opt/node
98 # 'pkg_new_opt' will be the installed version, such as to $HOME/.local/opt/node-v12.8.0
99 rm -rf "$pkg_common_opt"
100 ln -s "$pkg_new_opt" "$pkg_common_opt"
104 # web_* are defined in webi/template.bash at https://github.com/webinstall/packages
106 # if selected version is installed, re-link it and quit
109 # will save to ~/Downloads/$WEBI_PKG_FILE by default
112 # supported formats (.xz, .tar.*, .zip) will be extracted to $WEBI_TMP
117 pushd "$WEBI_TMP" 2>&1 >/dev/null
119 # remove the versioned folder, just in case it's there with junk
120 rm -rf "$pkg_new_opt"
122 # rename the entire extracted folder to the new location
123 # (this will be "$HOME/.local/opt/node-v$WEBI_VERSION" by default)
125 # ex (full directory): ./node-v13-linux-amd64/bin/node.exe
126 mv ./"$pkg_cmd_name"* "$pkg_new_opt"
128 # ex (single file): ./caddy-v13-linux-amd64.exe
129 #mv ./"$pkg_cmd_name"* "$pkg_common_cmd"
131 # ex (single file, nested in directory): ./rg/rg-v13-linux-amd64
132 #mv ./"$pkg_cmd_name"*/"$pkg_cmd_name"* "$pkg_commend_cmd"
140 # web_path_add is defined in webi/template.bash at https://github.com/webinstall/packages
141 # Adds "$HOME/.local/opt/node/bin" to PATH
142 webi_path_add "$pkg_common_bin"
145 pkg_post_install_message() {
146 echo "Installed 'node' and 'npm'"