Moving on with the BNB: Bread n’ Butter 🍞🧈 series, it’s time to look at the other half of the MERN stack: Node.js, Express, and Apollo.
This combo is fast, flexible, and free to use - powering everything from REST APIs to GraphQL endpoints.
Backend (Node.js/Express/Apollo)
Daily tools when wiring APIs
1. Modules (import/require)
- Split code into small files: 
db.ts,user.ts,article.ts - Node's bread and butter: everything is modular!
 - Example:
 
import { db } from './db';
import { user } from './user';
import { article } from './article';
2. Asyncronous operations (async/await)
- Almost everything on the backend is async: database queries, API calls, file system ops. That’s why async/await is your best friend.
 - Example:
 
const user = await db.user.findById(id);
3. Routing/Resolvers
- Express handles REST-style routes:
 
app.get('/user/:id', (req, res) => { ... })
- Apollo handles GraphQL queries/mutations:
 
userQueries.user = async (_: any, { id }: { id: string }) => { ... }
- Just like Next.js has pages, these wire up your API logic.
 
4. Middleware
- Functions that sit between requests and responses. Think of them as "filters" or "guards".
 - Express:
 
app.use((req, res, next) => { ... })
- Apollo:
 
expressMiddleware(server, { 
  context: async ({ req }: any) => { ... } 
})
- Examples: Authentication, Logging, Rate Limiting
 
5. Environment Config (dotenv)
- Never hardcode secrets. Use environment variables for things like PORT, DB_URI, API keys.
 - Example:
 
const port = process.env.PORT || 3000;
const dbUri = process.env.DB_URI || 'mongodb://localhost:27017/myapp';
6. Database Models (Mongoose)
- This is the backend’s “state” — persistent data.
 - Define structure and relationships using schemas.
 - Example:
 
const userSchema = new mongoose.Schema({
  name: String,
  email: String,
  password: String,
});
The Bread n’ Butter Flow:
Modules → Async/Await → Routing/Resolvers → Middleware → Env Config → Database Models
Master these, and you can wire up APIs for anything from a small SaaS to enterprise-scale systems.
I move forward in the next post with BNB: MongoDB & React Integration
How about you, this time, any personal “bread n’ butter” in backend? 
Anything you can’t live without? Share with me, I'm even more curious!!!
              






    
Top comments (0)