aka backend chaos, Postman errors, and drawing tokens with pens πβοΈ
Yess guys, I'm back with another weekly update (or a chaotic blog, same thing at this point).
This week was all about Express.js, learning backend basics and unlocking new dev girl powersπͺπ« .
From setting up servers, hitting Postman with 403s, figuring out tokens, to finally meeting JWTs β
it was FULL vibes and full chaos.π₯Ήπ«Ά
So let's dive into building a basic Express app for authentication (and yeah, some hand-drawn madness included to explain my logic π).and googling google πΈ
π Setting Up: Express Auth App Begins
Letβs initialise an Express app β super simple.
npm init -y # Step 1: Start Node project touch index.js # Step 2: Create entry file npm install express # Step 3: Add Express
Open it all in VS Code. IYKYK. π©π»βπ»
π Basic Auth β Signup & Signin
Letβs keep it minimal (but working):
β
POST /signup β save user info
β
POST /signin β validate + send token
β
Use express.json() middleware
β
Store users in an in-memory array (no DB rn, just memory lane π§ )
And hereβs what my logic sketch looked like:
Also here's how I planned storing tokens and user info π
(I added JWT later, ignore that for now π
)
π―/me
Endpoint β Authenticated Route
So I created an endpoint called /me that returns user details only if they send a valid token.
Because we love some privacy π
π« Hitting It with Postman
-
GET
for reading -
POST
for registering or logging in - Use
http://localhost:3000/me
to hit that private route
How I ran it:
node index.js
Now Postman just waits for your requests like:
π Signup Flow
Start with /signup
(yes I made spelling errors at first... dev things π)
Then hit /signin to receive your token ποΈ
π Use the Token in Headers
After you receive the token, you gotta copy it and paste it in the headers when hitting /me
.
β οΈ The token changes every time β itβs randomly generated by generateToken() in this version.
π§ Auth in Action
Now when I hit /me using the valid token β boom, it works!
Returns only my data π₯
And yeah, GET method it is π
Hereβs what I get in my terminal too β actual user info π₯
Now unless someone steals my token (pls donβt π),
they canβt access my /me
endpoint.
π€ Problem β But This Isnβt JWT Yet!
This whole setup uses a random token saved in memory.
That means every time we validate, we must query the users array.
Big no-no for real apps πΆβπ«οΈ
π§ Solution β Enter JWT (JSON Web Tokens)
JWT lets us sign and verify tokens β no need to store anything server-side.
It carries its own data and verifies itself π
Hereβs how I understood it (and drew it out π ): -
Some more doodles to make it clear ποΈ ( I drew thatπ₯Ή)
π Replacing Token Logic with JWT
Step 1: Install JWT
npm install jsonwebtoken
Step 2: Remove generateToken()
We donβt need it anymore.
Step 3: Create a secret key
const JWT_SECRET = "USER_APP";
Step 4: Sign JWT
When the user logs in, generate a JWT token like this:
const token = jwt.sign({ username: user.username }, JWT_SECRET);
π§Ύ Bonus Sketch: Encryption vs Decryption
I found this while figuring out how encryption works in JWT.
Hope it helps someone π
π
π JWT Verification: The /me Endpoint
Once youβve switched to JWTs, itβs time to verify them when users hit your protected route.
Hereβs how I did it in the /me
endpoint using jwt.verify()
π
π»Running the Final Flow (With JWT Now!)
Now letβs see it in action from start to finish, this time with JWT-powered logic.
π Step 1: Sign Up
π Step 2: Sign In (Get Your JWT Token)
itβs long, has 3 parts separated by dots (.), and carries your data securely : -
π§ Step 3: Authenticated /me
Route
Boom π₯ β youβre in!
This time it works without needing to check the DB β JWT handles the identity ποΈ.
And here's how the terminal looks when all things align perfectly β¨
πΈ Wrapping Up (for now...)
This was one wild ride through backend basics, but hereβs what we nailed:
β
Created a Node + Express app
β
Built basic auth logic with random tokens
β
Upgraded to secure JWT-based authentication
β
Tested it all via Postman
β
Cried once, debugged twice, and learned a LOT π΅βπ«π οΈ
πΈ MY github Repo : - [https://github.com/khushikumari239/Express-APP.git]
π¨ Whatβs Next?
This was Part 01 of my backend chaos β stay tuned for:
πΌοΈ Frontend integration
πΏ Real-time form handling
π And starting MongoDB (finally unlocking the M in MERN π)
Let me know if you vibed with this post (or if Postman scarred you too).
Until then β more bugs, more doodles, and more dev girly energy π
β¨
With π» & βοΈ,
Khushiiiβ€οΈ
raw and real. just me to you πΌ
Top comments (0)