▲ 2 r/node+1 crossposts

I updated express-generator-typescript to use zod for middleware validation

I've known about Zod, a JavaScript/TypeScript schema validation library, for a while, but I underestimated the size of its ecosystem. After using it for some form validation in React, I thought I'd see how well it integrated with Express. Sure enough, there were several middleware libraries for Zod + Express, so I decided to give one a try. I went with express-zod-safe because it fit my existing setup with very little effort.

Boom, that let me remove roughly 150 lines of custom validation and typing code. For context, the template created by express-generator-typescript is a simple CRUD app with four API endpoints. I hadn't realized how much boilerplate I'd written just to validate objects in the route handlers, including validator functions and some custom request/response types. I also replaced my environment variable validation code with Zod.

Express has been around for a while, but I still find it useful for small projects and demos. If you'd like a quick way to spin up an Express + TypeScript project, check out express-generator-typescript.

github.com
u/TheWebDever — 5 days ago
▲ 7 r/webdev

jet-id: Unique ID generator with id lengths based on the entropy you ask for

jet-id is an open source universal unique-ID generator I built similar to nanoid or uuid. Unlike other unique-id generators, you can specify how many random bits (entropy) you want, and it creates the shortest id string that provides at least that much entropy using the Crockford alphabet, with dashes automatically inserted for readability. Dash inserting makes sure that no segment grows greater than 10 characters.

125 bits of entropy is the default and it works both CLI and programmatically:

npx jet-id -e 80
# V2BJABVRJ-S1TWXS-NTQA3       (20 random characters, 22 with the dashes)

npx jet-id
# 9GNK14S3A-728HK9-5NJQS-HWETM (25 random characters, 28 with the dashes)

It also supports timestamped-IDs and monotonic-IDs (monotonic ids sort in creation order within a single millisecond).

import jetid from 'jet-id'

jetid.timed()    // '1M41J22ER-RND9M6-3CZAQ-XT8GR'
jetid.mono(125?) // '1M41J2ZPK-8K0000-GE29AYBQ27-4496ZM40-29JSNX4'

jet-id is really fast too. Check out these benchmarks

It's available right now on npm: https://www.npmjs.com/package/jet-id
Direct readme link: https://github.com/seanpmaxwell/jet-id#readme

Feedback, suggestions, and constructive criticism are very welcome (so are Github stars ⭐)

Feel free to reach out to me on GitHub or Reddit

u/TheWebDever — 12 days ago
▲ 5 r/node+1 crossposts

Typesafe formatting API endpoints with jet-paths

Built this for my React + ExpressJS project a few years ago to keep all of my endpoints in one place and reduce some of the boiler-plate for adding path/search parameters.

Up until recently only path parameters (and not search parameters) were type-safe. I just did a major update so now search parameters are type-safe'd using <> brackets:

const Paths = jetPaths({
    $path: '/api',
    Users: {
      $path: '/users',
      One: '/:id',              // <- path parameters
      Posts: {
        $path: '/posts',
        Get: '/all?<q!><page>', // <- search parameters
        Add: '/add',
      },
    },
 });

Paths.Users.Posts.Get({ id: 1 }, { q: 'foo' });
// Line above returns: '/api/users/1/posts/all?q=foo'

Paths.Users.Posts.Get({ id: 1 });   // TypeError: Missing search parameters
Paths.Users.Posts.Get()             // TypeError: Missing path parameters 

Note that the type-safety is just making sure that the parameters are present, a primitive, and for search parameters an array of primitives is also allowed. It doesn't type-safe string vs number.

github.com
u/TheWebDever — 15 days ago

express-generator-typescript v3 released, finally a module type instead of commonjs

Built this a few years ago to spin up new express projects. Due to compatibility issues with some libraries (i.e. KnexJS), I was setting the type to commonJS for the longest time. Finally the new express template project that's spin up is now type: "module"

https://github.com/seanpmaxwell/express-generator-typescript

u/TheWebDever — 15 days ago

Thinking about switching from an XR+ to a Funwheel X7 Long Range, what’s the best piece of advice you can give me?

A couple of reasons I want to this:

I live on a big hill and while my XR can go down the hill it can’t go up it.

I think the stock rails look boring. I like the WTF rails but that requires recalibration, which I think I cannot do because I have the latest firmware.

I like going for long cruises and while I doubt the real world range for the X7 is close to 40mi, ~30mi would still be pretty good.

I know I could tear my board apart and vsec it but at that point I think I’m better off just getting an X7.

Thoughts?

reddit.com
u/TheWebDever — 3 months ago

Switching from Pixel 10 to iPhone 13 mini, what is the best piece of advice you can give me?

I'm sick of modern phones. They're big, they're heavy, they are a pain in your pocket when sitting in the car. I want a compact smartphone. I have a pixel 5 but it no longer receives security updates. iPhone 13 mini is the smallest smartphone I could find which still receives security updates. I don't care about fancy features (AI/high res photos). I just want to call, text, take some pics, use MFA apps like Proton/Microsoft authenticator, and some other common apps like Venmo/Chase/Spotify etc, and that's about it.

I haven't used an iPhone since 2011 though so this will be a big shift for me.

reddit.com
u/TheWebDever — 3 months ago
▲ 1 r/UsbCHardware+1 crossposts

Need a solution for 3 laptops and 1 desktop to share 2 monitors.

For computers I have:

​

work laptop (M1)

personal laptop (m4)

Linux laptop (dell xps 2019)

a gaming desktop tower

​

The monitors are:

Dell 3821dw, connected by usb-c for laptops and DP for tower

Dell 2421d, connected by HDMI for laptops and not connected to tower

​

Right now I'm just manually switching all the cables, which I'll probably keep doing cause I can't really find a KVM or think of a KVM combo that will work. One thought that crossed my mind was doing a 3 laptop kvm switch with the monitor's usb-c hub (to go from laptop to desktop) but I'm hesitant cause the monitor may just revert to the tower when changing laptops and I still don't get to use the side monitor with my desktop.

​

Maybe someone out there has a single product that will work or found a way to combine multiple KVM switches together? Let's suppose you were in my shoes, money was not an issue but space was and you had to stick to this setup.

reddit.com
u/TheWebDever — 4 months ago
▲ 39 r/DIY

My dining area has been having a really bad sugar ant infestation. I went to the hardware store an bought boric acid powder and created a 2-to-1 powdered-sugar/boric-acid powder. I sprinkled a lot of this stuff (and I mean a lot) around 2 of the 3 walls of my dining room. As you can see by the pics the ants are clearly eating the bait. Although now I'm wondering if I should've put more poison in there because after 8 days I'm still seeing ants.

I found the 2-1 mixture recommendation from some other pest control tutorial and originally didn't want to add more poison cause a google search said too much poison will cause ants to ignore the bait.

Before going through the trouble of cleaning up the old bait and making more I thought I'd make a reddit post. What do you guys think? Could I just maybe be facing multiple large nests and 8 days isn't it enough to kill all of them. I'm also worried the ants are just separating the sugar from the poison; although, this seems unlikely since I stirred the sugar/acid together in a bowl.

Update: 2 days later
So as some said the ants want liquid not powder and were capable of separating the sugar from the poison in powered form. So I decided to switch to liquid. Finding a recipe was hard cause every tutorial for liquid bait had something different. What I finally did was:

1 cup water + 1 half cup of powered sugar + 2 teaspoons boric acid (which is 4% of one cup which seems like a good number. Terro ant traps use 5% borax).

I put down some aluminum foil and put a couple of spoon fulls of the bait on the foil. 24 hours later, significant decrease in ant activity. I've only seen 1 stumbling ant so far. I saved the leftover bait in Tupperware and will put fresh bait everyday till I see zero ants. Thanks for the feedback!

https://preview.redd.it/dagbuozv9kyg1.jpg?width=1045&format=pjpg&auto=webp&s=7a4e40a4914c2fb1fbafff4f98c73e296c7854b3

https://preview.redd.it/kjbzo9by9kyg1.jpg?width=4000&format=pjpg&auto=webp&s=2fa67075d3c14b30a184a05dd40c2beb0d9aa363

reddit.com
u/TheWebDever — 6 months ago