Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
105
rated 0 times [  111] [ 6]  / answers: 1 / hits: 5721  / 11 Years ago, mon, february 3, 2014, 12:00:00

I'm running a node script from bash. Something like:



#!/bin/bash
echo Executing mynodescript.js...
node mynodescript.js


Inside mynodescript.js I have a console.log(Hello from mynodescript.js). How can I do to output it on my terminal window? So executing the bash script above would output something like:



> Executing mynodescript.js...
> Hello from mynodescript.js

More From » node.js

 Answers
12

The following code in your node script should work:
console.log('some text');



If it doesn't, make sure your PATH is correct within the shell script when executing node. The path to your node binary isn't set at the system level (within /etc/paths) then you may need to use the /absolute/path/to/node nodescript.js within the shell script.



If that isn't the issue, verify your node script syntax is correct.


[#48106] Sunday, February 2, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daja

Total Points: 407
Total Questions: 103
Total Answers: 103

Location: Ghana
Member since Sun, Mar 27, 2022
2 Years ago
daja questions
Tue, Dec 21, 21, 00:00, 2 Years ago
Thu, Apr 23, 20, 00:00, 4 Years ago
Fri, Sep 6, 19, 00:00, 5 Years ago
Tue, Jul 23, 19, 00:00, 5 Years ago
;