Skip to content

Instantly share code, notes, and snippets.

@burkeholland
Created April 17, 2019 16:14
Show Gist options
  • Select an option

  • Save burkeholland/222babcec897fb2b4cff2ef988074618 to your computer and use it in GitHub Desktop.

Select an option

Save burkeholland/222babcec897fb2b4cff2ef988074618 to your computer and use it in GitHub Desktop.

Sometimes I wonder if I know much of anything at all. Just a few weeks ago I was talking to a friend who mentioned off-hand, "you would never run an application directly against Node in production". I nodded vigerously to signal that I also would never ever run against Node in production because everyone knows that. But I didn't know that! Why didn't I know that?!?!

If I was to draw a Venn Diagram of what I know vs what I feel like everyone else knows, it would look like this...

What I know VENN

There is a better diagram created by Alicia Liu that kind of changed my life. It says that it's more like this...

Alicia's Venn Diagram

It's in the spirit of that diagram that I would like to share with you what I now know about running Node apps in production. Perhaps our relative Venn Diagrams don't overlap on this subject.

First off, let's address the statement "never run apps directly against Node in production".

Never run directly against Node in production

Maybe. But maybe not. Let's talk about the reasoning behind this statement.

Let's say we have a simple Node Express server. The simplest Express server I can think of...

const express = require("express");
const app = express();
const path = require("path");
const fs = require("fs");
const port = process.env.PORT || 3000;

// viewed at http://localhost:3000
app.get("/", function(req, res) {
  res.send();
});

// this will crash the server
app.get("/read", function(req, res) {
  fs.createReadStream("not-found-txt");
});

app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment