Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to run node.js interactively in Emacs on Windows

I thought this would work:

(defun my-node ()
  (interactive)
  (pop-to-buffer (make-comint "my-node" "node")))

But when I do M-x my-node and enter 1+1 in the comint buffer, it does not display any output.

This is in Emacs 24.0.50.1 on Windows 7 and NodeJS is installed without any special configuration.

Calling node.js non-interactively as in M-x compile RET node hello-world.js RET works fine. Running node interactively in cmd works fine.

This might be related: when I run M-x shell and enter node in the shell buffer and then enter 1+1, it doesn't display the result. I must be missing something very basic.

Update:

Probably related: emacs/Python: running python-shell in line buffered vs. block buffered mode - Stack Overflow

like image 520
Yoo Avatar asked Jan 18 '12 12:01

Yoo


People also ask

How do I run a node js script in Windows?

The usual way to run a Node. js program is to run the globally available node command (once you install Node. js) and pass the name of the file you want to execute. While running the command, make sure you are in the same directory which contains the app.

How do I run node in Visual Studio?

In Visual Studio, go to Tools > Get Tools and Features. In the Visual Studio Installer, select the Node. js development workload, and select Modify to download and install the workload.


1 Answers

The simplest way to have node.js (tested using node v0.8.1) as an inferior shell under Emacs is to use the js-comint package. Then, set (setq inferior-js-program-command "node --interactive") to force node to run in interactive mode. The command M-x run-js will then open the interpreter.

Similarly, you can easily verify that node --interactive works within an eshell.

like image 113
barik Avatar answered Oct 11 '22 14:10

barik