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.
-
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 -lor thepscommand with something likeps -ef. You can usegrepto filter the output, but what you need to find is the process ID (PID) of your build process so you can stop it withkill. You may also want to read up onpgrepandpkillwhich are handy for this process.Note that in your example you use
bgwhen it’s not appropriate.bgis for this sequence: 1. start a job in your shell’s foreground, 2. suspend that job with CTRL-Z, 3. usebgto tell the shell “allow this job to continue executing, but detached from my tty in the background”. (again,jobsis what you are looking for here).For the bigger picture, there’s no need or benefit of running that
coffeecommand 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.
Originally posted 2013-12-26 03:15:16.