How to get back to the command line after launching a Node.js script?

28,111

Solution 1

Press Ctrl+C to terminate the program and get back to the shell prompt.

If you want a program to run in the background and return you to a shell prompt, append an ampersand (&) to the end of the command. For example:

node test.js &

Solution 2

Just open a new tab by pressing Cmd-T, or a new window (using Cmd-N). You want to get warning/error messages that program sends to your terminal.


You can also use screen to get multiple... er... terminals in a single tab/window.

Press Ctrl-A Ctrl-C to create a new terminal, Ctrl-A Ctrl-N or Ctrl-A Ctrl-P (repeatedly) to go to the next and previous terminals. Type exit in all screen terminals to leave.


Regarding node: Check the documentation -- it should be possible to start it as a background server.

Share:
28,111

Related videos on Youtube

Adam Halasz
Author by

Adam Halasz

Hi, I made 37 open source node.js projects with +147 million downloads. Created the backend system for Hungary's biggest humor network serving 4.5 million unique monthly visitors with a server cost less than $200/month. Successfully failed with several startups before I turned 20. Making money with tech since I'm 15. Wrote my first HTML page when I was 11. Hacked our first PC when I was 4. Lived in 7 countries in the last 4 years. aimform.com - My company adamhalasz.com - My personal website diet.js - Tiny, fast and modular node.js web framework

Updated on September 18, 2022

Comments

  • Adam Halasz
    Adam Halasz over 1 year

    I'm on a Mac OS X 10.6.7.

    I started a node.js script, which starts an HTTP server.

    The problem is that I lost the command line, it looks like this:

    $me cd directory
    $me node test.js
    Message from test.js: Server is running on localhost
    ..|
    

    | = indicates the caret

    It's possible to write but I'm unable to run any code, it's like writing a plain string, how can I get back to the commmand line?

    Sorry I'm really noob in terminal :)

  • Chris Nava
    Chris Nava about 13 years
    If you want to keep it running press [ctrl] + [z] then type bg
  • Dan Rosenstark
    Dan Rosenstark over 12 years
    Thanks @ChrisNava I never knew that you could do bg and fg without using %1 (or %something). Great point!