- I used Bun for this project not as a runtime but as a tool caller. Hence,
bunx @nest/cli new - Choose you package manager. I chose
npmbecause it is tried and tested but also, because of this thing (This has so many issue referencings that I lost count) - Immediately ditch the
tsccompiler because the build times were attrocious. Use the new and shinyswc
{
"$schema": "https://json.schemastore.org/nest-cli",
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"deleteOutDir": true,
"builder": "swc"
}
}
- And install it as
bun add -d @swc/core @swc/cli - Then, install the other dependencies.
bun add drizzle-orm pg @nest/config @nestjs/passport passport passport-jwt - Install the dev dependencies as:
bun add -d drizzle-kit @types/pg @types/passport-jwt - Set up your
envfile as explained in the example file. - Create your schema to fit your needs. In my case it looks like this
- Create a globally accessible instance of the db for queries later.
- Create the DB module so that instances of DB can be imported to other modules.
- Install the most famour and probably tje most used package in NestJS. i.e
bun add class-validator class-transformer - Make your migrations and push to db.
bunx drizzle-kit generatebunx drizzle-kit migratebunx drizzle-kit push - Register your DB module in the main application module.
- Finally create your auth module with auth service, controller and write your logic.
Note: For the rest you can consult the git logs
Note 2: Apparently Math.random() is so predictable that only 2 or 3 numbers maybe required to get the seed. And while the cycle for Math.random() , maybe high, I will be using this package called nanoid, which gives me unique URL-friendly strings and is lightweight(like 118 bytes, wtf)
Note 3: If you want to check out my PRNG implementations like vonNeumann Method and so on, check out: my PRNG repo
Note 4: It was pretty obvious from the get go that in account creation, the password hashing was going to give me trouble, and hence, I wll be switching to bcrypt and not use Bun's native "hasher" But it was worth a shot.