Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I force execjs to use Node.js?

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.

like image 764
Max Avatar asked Mar 13 '12 15:03

Max


People also ask

How does node JS run JavaScript?

Both your browser JavaScript and Node. js run on the V8 JavaScript runtime engine. This engine takes your JavaScript code and converts it into a faster machine code. Machine code is low-level code which the computer can run without needing to first interpret it.

Which feature does node enable for JavaScript?

“A module that allows you to use feature flags (also known as feature flipping) in Node. js. You can enable/disable features programmatically or via an external configuration file. Any changes to the configuration file will update the module without requiring a restart.”


3 Answers

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

like image 151
Max Avatar answered Oct 01 '22 09:10

Max


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 
like image 39
drewsberry Avatar answered Oct 01 '22 09:10

drewsberry


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.

like image 24
Hauleth Avatar answered Oct 01 '22 10:10

Hauleth