31

I have a rails app, and I want to force execjs to user Node.js as the javascript runtime. How do I even check which runtime execjs is using?

Thanks.

Max
  • 15,157
  • 17
  • 82
  • 127

3 Answers3

32

I figured out how to set the javascript runtime. In config/boot.rb I put the following line: ENV['EXECJS_RUNTIME'] = 'Node'

Max
  • 15,157
  • 17
  • 82
  • 127
  • 4
    Better option is to set shell env variable `EXECJS_RUNTIME`. – Hauleth Jun 03 '13 at 07:56
  • Hey @ŁukaszNiemier, What's the value that has to be assigned to EXECJS_RUNTIME? I used **"export EXECJS_RUNTIME=/opt/node-v4.4.5-linux-x64/bin"**. But now its showing the error `wrong constant name /opt/node-v4.4.5-linux-x64/bin`. – learner Jun 16 '16 at 06:11
  • OK I did that now the error is **Gem Load Error is: Node.js (V8) runtime is not available on this system**. I don't want to install NodeJS from any package manager. So I downloaded NodeJS from [here](https://nodejs.org/dist/v4.4.5/node-v4.4.5-linux-x64.tar.xz). How can I tell rails to find node.js in the directory **/opt/node-v4.4.5-linux-x64/bin**? – learner Jun 16 '16 at 16:37
  • Is `/opt/node-v4.4.5-linux-x64/bin` on your path? If it is not, add it, otherwise open a new question to address this problem. – Max Jun 17 '16 at 06:48
21

While Max 's answer is perfectly valid and good if you want to globally set this option, it's worth noting that there's a simpler way to do it. To print out the current runtime, after importing ExecJS via require 'execjs', just run

puts ExecJS.runtime.name

And to set the current runtime, just use

ExecJS.runtime = ExecJS::Runtimes::Node
Community
  • 1
  • 1
drewsberry
  • 534
  • 5
  • 8
4

If you still have public/index.html then it will show you what JS engine is used. If you don't have one then here you go https://gist.github.com/2029491.

Hauleth
  • 22,873
  • 4
  • 61
  • 112
  • 10
    Thanks for this. I did not know you could do that. I also figured out how to set the javascript runtime. In config/boot.rb I put the following line: `ENV['EXECJS_RUNTIME'] = 'Node'`. – Max Mar 13 '12 at 19:14
  • @Max wish you'd put that in as an answer! – Chris Pfohl Feb 14 '13 at 21:46