1

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
2
  • It doesn't do this by default? Commented Feb 3, 2014 at 15:42
  • This is the default, unless something's changed. Maybe stdout is closed and reopened into a file? Maybe a logging library does this? Commented Feb 3, 2014 at 15:59

2 Answers 2

4

How about this

#!/bin/bash
echo "Executing mynodescript.js..."
node mynodescript.js 2>&1
Sign up to request clarification or add additional context in comments.

1 Comment

I didn't get to test this. It was working just the way I had it, I just had to restart my terminal. Thanks anyway.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.