Skip to toolbar

Practical dev majik and devops: Finding your node Linux process

Spread the love
14 / 100
Reading Time: 3 minutes

If you’re new (or beyond 42 years) to dev jobs, it might happen that..

  • you made some simple top-of-your-head Node server code
  • you ran the server with a $ node blahblahblah.js
  • …and left it running.

All is fine at this point, right? Absolutely. No funny-cat face yet needed. Alas:

  • later on, you logged in to the server, but have no idea how to “locate” your server as a Linux process

What was my Node server’s folder, again?!

Photo 1548681528 6a5c45b66b42?ixlib=rb 1.2
Photo by Ramiz Dedaković on Unsplash

Soooo…. you remember your cute proof-of-concept server, hazily whipped on top of express is listening to port 3000, that’s for sure.

..but you’ve got no fricking idea which process your node is

man in brown long sleeve shirt holding book in white wooden book shelf
Photo by cottonbro on Pexels.com

..and as said, yeah, it’s a couple of weeks since your last visit on this Linux box… and it’s kind of Friday afternoonish… and you kind of would like to get the momentum going.

Two friends: ps and history

ps ax | grep -i 'node'

And behold! Bingo!

Look at the result:

Image 1
  • importance of naming your entry point (ie the file that normally is index.js)
  • you can drill down more now that you’ve found the important thing, the pid number (in the screenshot it’s 640). There’s a whole lotta things that can be done. Google around for ‘linux ps’, ‘linux vtop’, ‘using vtop’

What is the ‘history’?

Linux and Macs have the command ‘history’. It’s really useful memory aide sometimes. History lists your entire command history, ie. the commands that you’ve entered into the shell. When sometimes running complex and long commands to run servers, or in doing any other devopsey magic, history can be really useful.

Just try it in the shell:

history
Again, in the philosophy of Linux and *nix systems: treat output from tools as a valuable data to be further processed with other tools. grep is your powerhouse for finding snippets of text when you can describe the approximate (or precise) format. ‘awk’ is another great tool, albeit a bit more complex. Awk allows for the usual programming-like complexity of building your text-mangling solutions.
history > mygoldstash.txt 

Sidetrack: of naming things

One of the most well-known “you’d never believe it to be so hard” -problems in coding is naming things! Naming is required in many places: naming files, scripts, commands, variables, you name it!

In the above drill, I am running this superb Gauntlet game on my VPS, using node. So I named the entry point file as gsrv (for “gauntlet server”). Fair enough. But I have to admit already a few weeks down the memory lane it might be hard to remember this, especially if I had several node processes going on at the same time.

Enjoy! See you back later.

Facebook Comments

Published by jukkasoft

Hi! A bit updated description. Code enthusiasta, technology optimist, but also a realist. In my blog I wrote 80% of technology related articles, mostly in English and Finnish. I like to envision and ponder about things, how life could be, what we are doing wrong today, and so on. "Invented" a facebook -like system in 2000, as a short product pamphlet. Haven't yet realized the 20+ ideas that might have become big things. Maybe learning this skill one of these days!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: