Cover image for Know when to fold 'em

Know when to fold 'em

jesseskinner profile image Jesse Skinner Originally published at codingwithjesse.com on ・2 min read

The last few weeks on Twitch, I've been working on the user authentication to use for my side projects, including my upcoming course The Joy of Svelte.

I wrote it in a generic way as Express middleware. It uses a MySQL database with express-session and express-mysql-session. It doesn't have any HTML, it just adds a REST API to your server with some routes like /auth/signup, /auth/login, /auth/forgot and /auth/reset. This way, each of my sites can have a different UI, and use fetch to do everything.

Oh man, I wasted so much time when I was building it. I wanted to try building the whole thing with pure ES modules. ES modules are now supported in Node without a flag, so I figured it's finally time to use them without a build process.

I wasted hours trying to get it to work. Of course Mocha doesn't work with ES modules yet. Eventually, I gave up and went with using a library called esm that gets things working somehow. When I thought I was done, and tried to add it to a Sapper project. Since it was now in my node_modules, and being transpiled by Rollup, it all broke. Sigh.

I was facing another never-ending black hole of googling and debugging. So you know what I did? I went and rewrote the ES modules to CommonJS syntax. It took three minutes.

Lesson is, just because a new feature is available, you still have to wait for your entire tool chain to catch up and adapt as well. It's fun to push the envelope, but it can get exhausting too. Sometimes it's faster to cut your losses and take another route.

As Kenny Rogers warns, "You got to know when to hold 'em, know when to fold 'em, know when to walk away and know when to run."

If you're curious about the authentication middleware, you can see the source code here. It's not perfect for everybody, but if you want to use it and think I should publish it to npm and document it, let me know.

If you're excited about The Joy of Svelte, it'll be launching soon. Sign up for the Coding with Jesse newsletter, and you'll get a subscriber discount as soon as it's ready.


Editor guide
victorioberra profile image
Victorio Berra

It also shows you which projects are fast to react and update their code to stay modern. It's important to use tooling that strives to stay up to date, especially with bug and security fixes. When dotnet core 3 launched, it took a very long time for many projects to catch up. Looking at you Swashbuckle.AspNetCore

jesseskinner profile image
Jesse Skinner Author

Excellent point, I hadn't thought of that.

sargalias profile image
Spyros Argalias

Yeah good points. Tools and features are there to help us, not get in our way. I've started having little patience for tools that detract from that and need too much configuration or googling for weird errors to get right. These days I always question "is the tool worth it for the trouble it provides"?

For example any ESLint rule that gets in my team's way 2 or 3 times, after discussion with my team that it's a false positive and the safety it provides is not significant, gets immediately disabled.

Something like Storybook however, even though setup takes a long time (one of the major downsides of it, in my opinion), was worth it. Same as some ESLint rules which can also be false positives sometimes, but are otherwise important.

EDIT: Grammar

jesseskinner profile image
Jesse Skinner Author

Yeah exactly. Sometimes it's worth the effort and risk. Sometimes you should give up.