Welcome to your first backend project!
This is a hands-on workshop where you'll build your very own backend server from scratch. Don't worry if you've never done this before — this guide will walk you through every step, explaining everything in simple terms.
This is a backend server that connects to an AI service called Groq. Think of it like this:
- You have a simple web page (frontend) where users can type questions
- Your backend server receives those questions
- The backend talks to Groq's AI to get smart answers
- The backend sends the answer back to the web page
In simple words: You're building the "middle person" that connects a website to an AI brain.
Imagine you want to build a chatbot or AI assistant on your website. You can't directly connect your website to AI services because:
- Security: You need to hide your secret API keys (passwords)
- Control: You want to validate what users send before passing it to AI
- Processing: Sometimes you need to modify or log the data
That's where a backend comes in. It's like a secure bridge between your website and external services.
By the end of this workshop, you will have:
- A working Node.js backend server
- An API endpoint that accepts questions
- Integration with Groq AI service
- A simple web interface to test your backend
- Understanding of how frontend and backend communicate
Think of a restaurant:
- Frontend = The dining area where customers sit and order (what users see)
- Backend = The kitchen where food is prepared (where the real work happens)
- API = The waiter who takes orders and brings food (connects frontend and backend)
In web development:
- Frontend: The website you see in your browser (HTML, CSS, JavaScript)
- Backend: The server that processes requests, talks to databases, handles business logic
- API: The communication channel between them (like a messenger)
Your backend will:
- Listen for incoming requests
- Process the data
- Talk to external services (like Groq AI)
- Send responses back
Before you start, you need a few tools installed on your computer. Don't worry — we'll explain what each one does!
What is it?
Node.js lets you run JavaScript code on your computer (not just in a browser). It's what powers your backend server.
How to check if you have it:
Open your terminal (Command Prompt on Windows, Terminal on Mac/Linux) and type:
node --versionIf you see something like v18.17.0 or v20.10.0, you're good!
Don't have it?
Download from nodejs.org — choose the LTS version (Long Term Support).
What is it?
A code editor — like Microsoft Word, but for writing code.
Download: code.visualstudio.com
What is it?
A tool to download code from GitHub and track changes.
How to check:
git --versionDon't have it?
Download from git-scm.com
You have two options:
- Open your terminal
- Navigate to where you want to save the project:
cd Desktop - Clone the repository:
git clone <your-repo-url>
- Go into the project folder:
cd Backend_workshop
- Go to the GitHub repository page
- Click the green Code button
- Click Download ZIP
- Extract the ZIP file to your Desktop
- Open the folder in VS Code
After downloading, you'll see these files and folders:
Backend_workshop/
├── index.js ← Your main server file (EMPTY — you'll write this!)
├── routes/
│ └── groq.routes.js ← Defines API endpoints (already written)
├── services/
│ └── groq.services.js ← Talks to Groq AI (already written)
├── .env ← Secret keys (you'll create this)
├── .env.example ← Template for .env file
├── package.json ← List of dependencies
├── node_modules/ ← Installed packages (appears after npm install)
├── index.html ← Simple frontend to test your backend
└── .gitignore ← Tells Git what files to ignore
This is intentionally empty! This is where YOU will write the backend code.
Think of it as the "main entrance" of your backend. It will:
- Import necessary packages
- Create the server
- Connect routes
- Start listening for requests
What are routes?
Routes are like different pages on a website, but for your backend.
For example:
/→ Health check (is the server running?)/ask→ Send a question to AI
The file groq.routes.js already defines these routes for you.
What are services?
Services contain the "business logic" — the actual work your backend does.
The file groq.services.js has a function that talks to the Groq AI API.
This file stores secret information like API keys.
Why is it important?
- You don't want to share your API keys publicly
.envis listed in.gitignore, so it won't be uploaded to GitHub
You'll create this file yourself in the next section.
This file tells Node.js:
- What your project is called
- What packages (libraries) it needs
- How to run scripts
You don't need to edit this file.
This folder appears after you run npm install.
It contains all the code libraries your project needs (like Express, Groq SDK, etc.).
NEVER EDIT FILES IN THIS FOLDER! It's auto-generated.
This is a basic web page you can open in your browser to test your backend.
It has:
- A text box to type questions
- A button to send the question to your backend
- A response area to show the AI's answer
.env is a special file that stores secret keys and configuration settings.
Think of it like a locked safe where you keep passwords.
- In your project folder, you'll see a file called
.env.example - Copy it and rename the copy to
.env - Open
.envin VS Code
It should look like this:
GROQ_API_KEY="your_api_key"
PORT="3000"
- Go to console.groq.com
- Sign up for a free account
- Go to API Keys section
- Click Create API Key
- Copy the key
- Paste it in your
.envfile:
GROQ_API_KEY="gsk_your_actual_key_here"
PORT="3000"
Because it contains secret keys! If you upload it to GitHub, anyone can steal your API key and use it.
That's why .env is listed in .gitignore — Git will ignore it and never upload it.
npm stands for Node Package Manager. It's like an app store for code libraries.
When you run npm install, it:
- Reads
package.jsonto see what packages you need - Downloads them from the internet
- Puts them in the
node_modules/folder
Open your terminal in the project folder and run:
npm installWhat you'll see:
- A progress bar
- Lots of text scrolling
- A message saying "added X packages"
What happens after:
- A
node_modules/folder appears - You're ready to code!
Once you've written your code in index.js, it's time to start the server!
In your terminal, run:
node index.jsIf everything is correct, you'll see:
Server running on port 3000
Congratulations! Your backend is now running!
Why? You forgot to run npm install
Fix: Run npm install first
Why? Your .env file isn't loading
Fix: Make sure you:
- Created the
.envfile (not.env.example) - Added
dotenv.config()in your code
Why? You didn't add your API key to .env
Fix: Open .env and paste your Groq API key
Why? Another program is using port 3000
Fix: Either:
- Close the other program
- Change the port in
.envto3001or8000
- Make sure your backend is running (
node index.js) - Open
index.htmlin your browser (just double-click it) - Type a question like "What is Node.js?"
- Click Send to Backend
- You should see an AI response!
Open your browser and go to:
http://localhost:3000/
You should see:
{"status": "Server is running"}This confirms your backend is alive!
Postman is a tool for testing APIs.
- Download Postman from postman.com
- Create a new POST request
- URL:
http://localhost:3000/ask - Body (JSON):
{ "prompt": "Explain what an API is" } - Click Send
- You should get an AI response!
Always run npm install before running your server!
Make sure you have Node.js version 16 or higher.
Check with: node --version
Make sure:
- The file is named
.env(not.env.txtor.env.example) - It's in the root of your project (same folder as
index.js) - You called
dotenv.config()in your code
If you see "port already in use":
- Close any other servers you're running
- Or change the port in
.env
Make sure you import everything you use:
import express from 'express';
import dotenv from 'dotenv';
import cors from 'cors';By completing this workshop, you now understand:
- What a backend is and why it's needed
- How to set up a Node.js project from scratch
- Environment variables and why they're important
- How to install dependencies using npm
- How to create a REST API with Express
- How to integrate external APIs (like Groq)
- How frontend and backend communicate (HTTP requests)
- How to test APIs using browsers and tools
What you built is a simplified version of real-world backends, but the concepts are the same!
In production systems:
| What You Built | Real Production |
|---|---|
index.js |
Main server file (same!) |
routes/ |
API endpoints (same structure!) |
services/ |
Business logic (same pattern!) |
.env |
Environment variables (same!) |
| Groq AI | Any external API (databases, payment systems, etc.) |
node_modules/ |
Dependencies (same!) |
The difference?
- Production backends have more routes
- They connect to databases (like MongoDB, PostgreSQL)
- They have authentication (login systems)
- They have error logging and monitoring
- They run on cloud servers (AWS, Azure, Google Cloud)
But the foundation is exactly what you just built!
Want to level up? Try these challenges:
- Add a new route — Create a
/helloendpoint that returns "Hello, World!" - Add input validation — Check if the prompt is too short or too long
- Add logging — Console.log every request that comes in
- Add rate limiting — Prevent users from spamming requests
- Connect to a database — Store all questions and answers in MongoDB
If you're stuck:
- Read the error message carefully — It usually tells you what's wrong
- Check your
.envfile — Most issues come from missing environment variables - Make sure you ran
npm install— Dependencies must be installed - Ask your workshop instructor — That's what they're here for!