Snippets about node

8 snippets

Back to all snippets

  1. SNP126

    Pages from a CMS in Stati

    Write the CMS's posts as Markdown before the build starts. A hook is too late.

    31 lines of js and json in 2 blocks, 8 lines of explanation.

    #A25 stati node
  2. SNP122

    Load .env files in Node without a package

    dotenv is built into Node now.

    2 lines of sh in 2 blocks, 7 lines of explanation.

    #42A node js
  3. SNP120

    Reverse proxy a Node app with nginx

    Your app listens on 3000, the world talks to nginx on 443.

    18 lines of nginx and sh in 2 blocks, 3 lines of explanation.

    #593 nginx node cmd
  4. SNP104

    Run a Node app as a systemd service

    Start on boot, restart on crash, logs in journalctl. No pm2 needed.

    20 lines of ini and sh in 2 blocks, 6 lines of explanation.

  5. SNP092

    Run TypeScript directly with Node

    No build step, no ts-node, for scripts and quick experiments.

    2 lines of sh and ts in 2 blocks, 7 lines of explanation.

  6. SNP084

    __dirname in ES modules

    It's gone in ESM. Here is the replacement, and the newer, nicer one.

    9 lines of js in 3 blocks, 4 lines of explanation.

    #45A js node
  7. SNP038

    Read a JSON file in Node

    Two ways, one of them without any fs code at all.

    4 lines of js in 2 blocks, 4 lines of explanation.

    #416 js node
  8. SNP036

    Sleep in Node without writing a timeout function

    Node ships a promise-based setTimeout, so the little helper from my old snippet isn't needed there.

    6 lines of js in 2 blocks, 6 lines of explanation.

    #B63 js node