Where do npm background scripts go?-Collection of common programming errors

I have a program which relies on another program being run so I added this build command to my package.json file

"scripts": {
    "start": "brunch watch --server",
    "build": "coffee server/modules/events/book_server.coffee &"
  }

so before I run my main script with npm start I run npm run-script build which makes my main script work, however when I quit my main script and then look for background processes with bg I get the message

> -bash: bg: current: no such job

so I decided to run npm run-script build again however the previous process must still have been running because I got the error message

events.js:66
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: listen EADDRINUSE
  at errnoException (net.js:776:11)
  at Server._listen2._connectionKey (net.js:917:26)
  at process.startup.processNextTick.process._tickCallback (node.js:244:9)

and when I tried to run my main program again I got the error

> TypeError: Cannot read property 'port' of null

My question is, where are these background scripts?

So far I have looked in all the obvious places including package.json‘s directory the directory for book_server.coffee and in node_modules but with no luck.

  1. So the background processes go into the background just running inside the OS but not attached to your shell’s tty. To find them, use jobs -l or the ps command with something like ps -ef. You can use grep to filter the output, but what you need to find is the process ID (PID) of your build process so you can stop it with kill . You may also want to read up on pgrep and pkill which are handy for this process.

    Note that in your example you use bg when it’s not appropriate. bg is for this sequence: 1. start a job in your shell’s foreground, 2. suspend that job with CTRL-Z, 3. use bg to tell the shell “allow this job to continue executing, but detached from my tty in the background”. (again, jobs is what you are looking for here).

    For the bigger picture, there’s no need or benefit of running that coffee command in the background as it is just a simple compliation step that should take on the order of a few milliseconds.

    For an amazingly-detailed “reread every year” level of depth, check out The TTY demystified.