Topic 3: Postman Configuration
📖 6 min read · 🎯 beginner · 🧭 Prerequisites: configuring-express, node-projects
Why this matters
You've built your first Express routes — great. But how do you actually test them? You can't just open a browser and send a POST request with a JSON body. You'd need to write code just to test your code, and that gets old fast. That's where Postman comes in. It's a free tool that lets you fire GET, POST, and any other HTTP request at your server in seconds, organize those requests into collections, switch between local and production environments with one click, and even run automated tests — all from a clean UI. No extra code needed.
What You'll Learn
- Install Postman and create your first GET and POST requests
- Organize related requests into Collections for better management
- Use Environment Variables to switch between dev, staging, and production
- Write JavaScript-based test scripts to automate API validation
- Run a full collection with the Collection Runner
The Analogy
Think of Postman as the quality-control lab at a car factory. The assembly line (your Node/Express server) churns out cars (API responses), but someone has to actually drive each model off the lot, check the speedometer, kick the tires, and confirm the AC works before shipping it to customers. Postman is that test driver — you describe exactly which car to drive (the endpoint URL and method), what road conditions to simulate (headers, body payload), and what a passing inspection looks like (status code, response shape). Collections are the test-drive checklists for each car model, and Environment Variables let you run the same checklist at the local garage (localhost) or the regional showroom (staging server) without rewriting a single step.
Chapter 1: Introduction to Postman
Postman is an API client that lets you craft HTTP requests, fire them at any server, and inspect every detail of the response — status code, headers, body, timing — through a clean graphical interface.
Key Features
- Creating Requests — Configure and send any HTTP method: GET, POST, PUT, DELETE, PATCH, and more.
- Inspecting Responses — View status codes, response headers, formatted JSON/XML body, and response time at a glance.
- Collections — Group related requests into named folders so your "Book API" calls don't mix with your "Auth API" calls.
- Environment Variables — Store values like
baseUrlorapiKeyper environment so you can switch fromlocalhostto production in one dropdown click. - Testing and Automation — Write JavaScript assertions in the "Tests" tab; the Collection Runner executes them in sequence and reports pass/fail per request.
Chapter 2: Installing Postman
Step 1: Download and Install
Head to the official Postman download page and grab the installer for your OS (Mac, Windows, or Linux). Run the installer; no terminal commands needed. Once installed, open Postman and sign in or continue without an account.
# Alternatively, install via Homebrew on macOS
brew install --cask postman
Postman launches to a workspace dashboard. You are ready to make your first request.
Chapter 3: Creating a GET Request
Step 1: Open a New Request Tab
- Click the New button (top-left) and select Request.
- Name it
Get Booksand click Save to Collection (create a collection calledBook APIif prompted).
Step 2: Configure and Send
- Set the method dropdown to GET.
- Enter the URL:
http://localhost:3000/books. - Click Send.
Postman displays the full server response beneath the request panel:
- Status: e.g.,
200 OK - Time: e.g.,
12 ms - Headers tab: see
Content-Type,X-Powered-By, etc. - Body tab: formatted JSON from your Express route
[
{ "id": 1, "title": "To Kill a Mockingbird", "author": "Harper Lee" },
{ "id": 2, "title": "1984", "author": "George Orwell" }
]
Chapter 4: Creating a POST Request
Step 1: New Request
- Click New → Request, name it
Add Book, and save it to theBook APIcollection.
Step 2: Configure the POST Request
- Set the method to POST.
- Enter the URL:
http://localhost:3000/books. - Open the Body tab, select raw, and choose JSON from the type dropdown.
- Paste the JSON payload:
{
"title": "To Kill a Mockingbird",
"author": "Harper Lee"
}
- Click Send.
Postman shows the server's response — typically a 201 Created with the newly created resource echoed back in the body. Every field (status code, headers, body) is inspectable without writing a single line of client code.
Chapter 5: Using Collections
Collections keep your requests organized the same way folders keep your files organized.
Step 1: Create a Collection
- Click New → Collection.
- Name it
Book APIand click Create.
Step 2: Add Requests to the Collection
- Drag and drop existing requests from the sidebar into the collection folder.
- Or create new requests directly inside the collection by right-clicking it and choosing Add Request.
Collections can also hold sub-folders (e.g., Books, Authors, Auth) and collection-level variables, headers, and pre-request scripts that apply to every request inside.
Chapter 6: Using Environment Variables
Environment variables let you parameterize your requests so the same collection works against localhost, a staging server, or production without manual edits.
Step 1: Create an Environment
- Click the gear icon (top-right) and select Manage Environments.
- Click Add to create a new environment.
- Name it
Development. - Add a variable:
- Variable:
baseUrl - Initial Value:
http://localhost:3000 - Current Value:
http://localhost:3000
- Variable:
- Click Add to save.
Repeat for a Staging environment pointing at your staging host.
Step 2: Use Variables in Requests
Replace the hardcoded URL in your requests with the variable:
{{baseUrl}}/books
Select Development from the environment dropdown (top-right corner) and click Send. Postman resolves {{baseUrl}} to http://localhost:3000 at runtime. Switch to Staging and resend — no URL editing required.
Chapter 7: Writing Tests
Postman's Tests tab accepts JavaScript using the pm (Postman) API, letting you assert response properties automatically on every send.
Step 1: Add Tests to a Request
- Open any request (e.g.,
Get Books). - Click the Tests tab.
- Enter your assertions:
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Response time is less than 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});
pm.test("Content-Type is application/json", function () {
pm.response.to.have.header("Content-Type", "application/json");
});
- Click Send.
The Test Results panel below the response body shows a green checkmark or red X per test, with the failure message if an assertion fails. No external test runner needed — Postman evaluates the scripts in-browser after each response arrives.
Chapter 8: Automating Workflows with the Collection Runner
The Collection Runner executes every request in a collection in sequence — complete with pre-request scripts, tests, and environment variable resolution — making it a lightweight integration test suite.
Step 1: Create a Test Collection
- Click New → Collection, name it
Book API Tests, and click Create. - Add requests to it — include all relevant pre-request scripts and test assertions on each request (see Chapter 7).
Step 2: Add Requests to the Collection
Populate the collection with your full API flow: authenticate → create a resource → fetch the resource → update it → delete it. Each request can reference data extracted from the previous response via pm.environment.set("bookId", jsonData.id).
Step 3: Run the Collection
- Click the collection name to open its details panel.
- Click the Run button → the Collection Runner opens.
- Configure run options:
- Environment: choose
DevelopmentorStaging - Iterations: how many times to loop through all requests (useful for load-style smoke tests)
- Environment: choose
- Click Run Book API Tests.
Postman executes each request in order and displays a live pass/fail summary. Failed tests surface the exact assertion message so you can pinpoint broken endpoints immediately.
flowchart LR
A[Collection Runner Start] --> B[Request 1: GET /books]
B --> C{Tests pass?}
C -- Yes --> D[Request 2: POST /books]
C -- No --> E[Log failure & continue]
D --> F{Tests pass?}
F -- Yes --> G[Request 3: DELETE /books/:id]
F -- No --> E
G --> H[Runner Report]
E --> H
🧪 Try It Yourself
Task: Build a two-request collection that creates a book and then fetches all books, with a test that confirms the new book appears in the list.
- Start your local Express server on port 3000 with a
/booksroute that stores books in an in-memory array. - Create a
POST /booksrequest in Postman with this body:
{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald"
}
- In the Tests tab of the POST request, capture the returned book ID:
var jsonData = pm.response.json();
pm.environment.set("newBookId", jsonData.id);
pm.test("Book was created", function () {
pm.response.to.have.status(201);
});
- Create a
GET /booksrequest. In its Tests tab, assert the new book exists:
var books = pm.response.json();
var found = books.some(b => b.id === pm.environment.get("newBookId"));
pm.test("New book appears in list", function () {
pm.expect(found).to.be.true;
});
- Save both to a collection and run it via the Collection Runner.
Success criterion: Both requests show green checkmarks in the Runner report, and the console confirms the new book ID is present in the GET response.
🔍 Checkpoint Quiz
Q1. What is the purpose of Environment Variables in Postman?
A) To store secret keys permanently in your source code
B) To parameterize request values (like base URLs) so the same collection works across dev, staging, and production
C) To define the HTTP method for a request
D) To format JSON responses automatically
Q2. Given this Postman test script, what condition causes it to fail?
pm.test("Response time is less than 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});
A) The server returns a non-200 status code
B) The response arrives in 600 ms
C) The response body is not JSON
D) The request method is POST instead of GET
Q3. You want to chain two requests in the Collection Runner so the second request uses the id returned by the first. Which approach achieves this?
A) Hardcode the ID in the second request URL
B) Use pm.environment.set("id", value) in the first request's Tests tab, then reference {{id}} in the second request
C) Run both requests in separate collections
D) Use a global variable set at install time
Q4. What does clicking Run on a Postman Collection open, and what does it execute?
A) The terminal, which runs npm test
B) The Collection Runner, which executes all requests in the collection in sequence along with their pre-request scripts and test assertions
C) A browser tab that loads your API documentation
D) The Environment Manager where you set base URLs
A1. B — Environment Variables let you define values like baseUrl per environment, so you can swap from localhost to staging with one dropdown change instead of editing every URL.
A2. B — The test calls .to.be.below(500), so any response time ≥ 500 ms (e.g., 600 ms) fails the assertion. Status code and body format are not checked here.
A3. B — pm.environment.set("id", value) in the first request's Tests tab stores the value at runtime; {{id}} in the second request URL or body resolves it when the Runner reaches that step.
A4. B — The Run button opens the Collection Runner, which iterates through every request in the collection in order, executes pre-request scripts, sends the request, and evaluates all test assertions, then shows a pass/fail summary.
🪞 Recap
- Postman is a GUI API client for sending HTTP requests, inspecting responses, and writing automated assertions without writing client code.
- Collections group related requests together and can be executed end-to-end via the Collection Runner.
- Environment Variables (e.g.,
{{baseUrl}}) let you switch between development, staging, and production with a single dropdown selection. - The Tests tab accepts JavaScript using the
pmAPI; assertions run automatically after every response. - The Collection Runner executes requests in sequence, evaluates all tests, and produces a pass/fail report — turning your Postman workspace into a lightweight integration test suite.
📚 Further Reading
- Postman Official Documentation — the source of truth for every Postman feature
- Postman Collection Runner Guide — deep-dive into iteration counts, data files, and CI integration
- pm API Reference — full reference for
pm.test,pm.expect,pm.environment, and more - ⬅️ Previous: Node Projects
- ➡️ Next: Working with package-lock.json to Lock the Node Modules Versions