Tag: Node
-
Express router for better code organisation
A Node/Express app I’m working on has been sprouting routes so much that the server.js file has swollen to 800 lines – way past my 200-250 comfort zone, so it’s time to organise the routes into their own files. That seems like a good topic for a beginner blog post, so let’s dive in. Imagine…
-
npm ERR! Exit handler never called!
I quite like GitHub scanning all my code and sending me security advisories. Here’s today’s: With these, and my dependabot alerts, fixing them is usually just a matter of pulling down the project, running an npm update, building any artifacts, then pushing it back up. But today, not so: package-lock.json It’s probably worth revisiting what…
-
Code reuse by publishing to NPM
If you find yourself copying over a source file from one Node project to another because it’s a handy utility you wrote and are used to using, you’re only doing it half right. A better way to do this is to publish your utility to the Node Package Manager (NPM). That way you can just…
-
Uploading files to a web app with Node
My default approach to web apps at the moment is Node/Express SSR. I needed to have users be able to upload files this week, and as usual there’s an express middleware that makes it trivial. This post just steps through using multer to make it simple to enable file uploads on your website. Express &…
-
Authentication basics for Node apps
Pretty much every serious web app needs to include a way for users to log in securely and to be served their content. Since there’s a lot of complexity in this, it’s highly advisable to use good libraries to support this. In a future post we’re going to use those libraries, but first I want…
-
Deploying a Node app in Docker
When I wrote the install instructions for mdserver (little Markdown server Node app) on it’s github page it was something like: Which is great if you know how to do those things (they are bread and butter to a web dev) but not if you’re a self-hoster who just wants a web server that converts…
-
Quick & Dirty auth with nginx & Node
One of the basic requirements for any serious web app is a proper users/roles/authentication system – but if you’re just throwing up a utility of some kind on a public IP for testing, and you don’t want it to be abused, then this could be an option. There’s a few components: I briefly discussed web…
-
Testing Node.js apps – Mocha, Chai, and Supertest
Bruno is a great open source Postman/Insomnia replacement, and I’ve been using it for basic tests of my node servers using the built in asserts and loving it. This is pretty great, and I gather it’s also possible to go beyond this and write tests in JS in Bruno. I believe it also has the…
-
Simple SQLite in Express
I don’t have experience with SQLite and want to shift one of my apps over from Mongoose since apparently SQLite is much more capable than I imagined. My usual tactic when trying something new is to try and get a minimal project working on it, so what follows is the simplest possible node/express REST API…
-
Adding Front Matter To mdserver
The very first issue I opened on mdserver – my server project that serves HTML from markdown files – was that the title of the page (which shows in the browser tab, and is used for browser bookmarks) needed to be set inside the markdown file, rather than generated from the file name. I didn’t…