Per this vim wikia entry you could create a shell execution to new buffer script and then extend it to run your code using node.
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>) function! s:RunShellCommand(cmdline) let isfirst = 1 let words =  for word in split(a:cmdline) if isfirst let isfirst = 0 " don't change first word (shell command) else if word =~ '\v[%#<]' let word = expand(word) endif let word = shellescape(word, 1) endif call add(words, word) endfor let expanded_cmdline = join(words) botright new setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap call setline(1, 'You entered: ' . a:cmdline) call setline(2, 'Expanded to: ' . expanded_cmdline) call append(line('$'), substitute(getline(2), '.', '=', 'g')) silent execute '$read !'. expanded_cmdline 1 endfunction command! -complete=file -nargs=* RunJS call s:RunShellCommand('node '.<q-args>)
Then if you run
:RunJS % you should get a new buffer with the output of your node.js execution. Optionally you can call things directly using
I highly recommend https://github.com/Shougo/vimshell.vim for this purpose.
Its a vim plugin that allows you to run a terminal within vim. You can open the terminal in a new tab with
or quickfix window with
then you can run commands as usual, i.e.