πŸ”₯ How to exit node terminal

πŸ”₯ How to exit node terminal
Photo by Phil Botha on Unsplash
44 sec reading time ⏲

What to do?

Well, have you ever been in the position to run JavaScript and you do not want to open the console developer and then run node on your terminal (because you had it open anyways), run the code you wanted and then you start trying to escape that prison, well this is my history when I tried to do it.

➜ node
> const d = new Date()
undefined
> d.now()
Thrown:
TypeError: d.now is not a function
> d
2020-04-27T16:45:45.723Z
> exit
Thrown:
ReferenceError: exit is not defined
> exit()
Thrown:
ReferenceError: exit is not defined
> /q
Thrown:
/q
^

SyntaxError: Invalid regular expression: missing /
> /exit
Thrown:
/exit
^

SyntaxError: Invalid regular expression: missing /
> .exit

There you go, you can exit node console by doing one of the following:

  • .exit πŸ‘ˆ this is is pretty cool
  • process.exit()
  • process.kill(process.pid)

    • You can also run process.kill(process.pid, 'SIGTERM'), this is to send the signal to the process you can capture that signal and do something about it
  • Press Ctrl + C twice