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...
There is a better diagram created by Alicia Liu that kind of changed my life. It says that it's more like this...
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".
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}!`));