Note: I actually did use this org-babel page for some of it, but it wasn't enough for me to really figure out what was going on.
PATH. They do support debian-based systems (including Ubuntu, which I use) but they don't use the traditional PPA system. Instead they have different installs for the different versions - but they do have a Long-Term Support (LTS) version which I'm hoping updates so that's what I installed.
curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash - sudo apt-get install -y nodejs
As of this writing it install version 12.19.0, versus the Ubuntu 20.04 version of 10.19.0.
Besides installing node you have to make sure that you add
js to your org-babel set up.
(org-babel-do-load-languages 'org-babel-load-languages '((js . t)))
If you already have other languages added this just goes in the same block.
(org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t) (shell . t) (emacs-lisp . t) (latex . t) (ditaa . t) (js . t) (python . t) (jupyter . t) ))
js blocks (e.g.
#+begin_src js :results output :exports both).
Here's a simple output block.
var x = 'apple' console.log(x) var y = 'banana' console.log(x + y)
One thing to note is that this doesn't seem create sessions that persist across blocks. Even though I defined
y in the previous block, this next block raises an error because it doesn't think I've defined
If you try and put a session argument in the org-babel header you'll get a message saying "Session evaluation with node.js not supported". According to the org-babel-js documentation you can put in special headers to run the code in an alternate REPL, but I tried it and the output ends up in a separate buffer rather than showing up in the org-document, which seems to kind of lessen the usefulness of it. Also the js-comint version dumps extra text into the REPL as well.