How To Gracefully Shut Down Express.js

What happens when you try to shut down an Express.js server while a user is connected to it?

var app = require('express')();

app.get('/', function( req, res ){
  
  // respond after 10s
  
  setTimeout( function(){ 
    res.send( 'all done!' ); 
  }, 10000 );
});

app.listen( 5000 );

This is a simple express server that waits ten seconds before sending a response to a user.

Let’s find out what happens when I connect to it and shut the server down before it responds to me.

Continue reading How To Gracefully Shut Down Express.js

Let Me Know What I Can Do Better

“But you already have a good physique!”, Oscar replied, his face matching the level of surprise in his voice.

Oscar’s a regular at the gym I’ve been going to for the last few months. We’d never spoken before today, but I was at the dips station when he wanted to use it so he started a conversation.

He did his dips flawlessly, so I asked him to watch my set and tell me where I can be better.

After the workout, I told him if he ever sees me doing an exercise improperly or has a tip to help me improve, he shouldn’t hesitate to let me know.

Getting advice at the gym

He seemed genuinely surprised that I’d take advice from him; maybe because it seems like I already know what I’m doing.

Thing is, the first time I ever worked out was just three years ago.

I still have no idea what I’m doing.

Continue reading Let Me Know What I Can Do Better