How to access a return value from a node script in BASH?

@Daniel Lizik gave an good answer (now deleted) for the part: how to output the value, e.g. using his answer:

#!/usr/bin/env node
function f() {
   return "test";
}
console.log(f())

And for the part how to capture the value in bash, do exactly as in your question:

#!/bin/bash
val=$(node app.js)
echo "node returned: $val"

the above prints:

node returned: test

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)