Saturday, 27 June 2020

Mastering Node.js

Menjalankan Aplikasi NodeJS di Background


Untuk menjalana aplikasi nodejs di bacground kita dapat menggunakan pm2 [3]

sudo npm install pm2@latest -g
cd /path/to/project
pm2 start --name="Project Name" npm -- start

Referensi

  1. Node.js Crash Course Tutorial, https://www.youtube.com/playlist?list=PL4cUxeGkcC9jsz4LDYc6kv3ymONOKxwBU
  2. How to Manage Multiple Node Versions in MacOS. (2021 Guide), https://chamikakasun.medium.com/how-to-manage-multiple-node-versions-in-macos-2021-guide-5065f32cb63b
  3. PM2, advanced, production process manager for NodeJS, https://pm2.keymetrics.io
  4. How to Run a Npm Start Script With PM2, https://coderrocketfuel.com/article/how-to-run-a-npm-start-script-with-pm2

Wednesday, 29 April 2020

Set a default parameter value for a JavaScript function

From ES6/ES2015, default parameters are in the language specification.
function read_file(file, delete_after = false) { // Code }

// the `= {}` below lets you call the function without any parameters 
function myFor({
 start = 5,
 end = 1,
 step = -1
} = {}) { // (A) // Use the variables `start`, `end` and `step` here ··· }

Pre ES2015,

function foo(a, b) {
 a = typeof a !== 'undefined' ? a : 42;
 b = typeof b !== 'undefined' ? b : 'default_b';...
}

Referensi

  1. Set a default parameter value for a JavaScript function, https://stackoverflow.com/questions/894860/set-a-default-parameter-value-for-a-javascript-function