Backend with Node.js and Express
The API that a tester sends requests to is code on a server. When you have built a small one yourself, its status codes, its checks, and its error messages stop being a mystery. This page builds a small REST API in Express, then tests it the way an SDET would.
9 min read9 মিনিটে পড়া যায় · 7 sections7টি সেকশন · 14 sources14টি সোর্স · updated Nov 2026আপডেট: Nov 2026
A request walks the middlewareএকটা অনুরোধ মিডলওয়্যারের ভেতর দিয়ে হাঁটে
See a request pass middleware, reach a route, and hang when next() is missing.একটা অনুরোধ মিডলওয়্যার পার হয়ে রুটে পৌঁছায়, আর next() না থাকলে ঝুলে যায়: তা দেখুন।
You’ll learnআপনি শিখবেন
- What a middleware gets: req, res, nextমিডলওয়্যার কী পায়: req, res, next
- Why a wrong Content-Type leaves req.body undefinedভুল Content-Type-এ কেন req.body undefined
- Why a missing next() hangs the requestnext() না থাকলে কেন অনুরোধ ঝুলে যায়
- Which handler answers an unknown path or a throwঅজানা path বা throw-এ কোন হ্যান্ডলার উত্তর দেয়
What it is
Express is a routing and middleware web framework Source 4সোর্স 4. An Express application is a series of middleware calls that run during the request-response cycle Source 4সোর্স 4. Express needs Node.js 18 or higher, and you install it with npm install express Source 2সোর্স 2.
Routing is how the endpoints of an app respond to client requests Source 3সোর্স 3. You define routes with methods of the app that match the HTTP methods, such as app.get() and app.post() Source 3সোর্স 3. A route path, together with a request method, defines an endpoint where requests can be made Source 3সোর্স 3.
REST is a set of architecture constraints for distributed systems Source 11সোর্স 11. Beginners can take a REST API to mean an HTTP service that standard web libraries and tools can call Source 11সোর্স 11.
API Testing with Postman explains HTTP methods and status codes. This page is the other side: the server that sends them.
সহজ English
Express is a web framework built around routes and middleware Source 4সোর্স 4. It needs Node.js 18 or newer, and you install it with npm install express Source 2সোর্স 2.
Routing is how the endpoints of an app answer client requests Source 3সোর্স 3. You write routes with app methods named after the HTTP methods, like app.get() or app.post(), and a method plus a path makes one endpoint Source 3সোর্স 3.
REST is a set of design rules for distributed systems Source 11সোর্স 11. As a beginner, you can think of a REST API as an HTTP service that normal web tools can call Source 11সোর্স 11.
API Testing with Postman explains methods and status codes. This page shows the server that sends them.
বাংলা ব্যাখ্যা
Express হলো একটা routing আর middleware web framework Source 4সোর্স 4। একটা Express application আসলে কিছু middleware call-এর ধারা, যেগুলো request-response cycle-এর সময় চলে Source 4সোর্স 4। Express-এর জন্য Node.js 18 বা তার পরের version লাগে, আর install করা হয় npm install express দিয়ে Source 2সোর্স 2।
Routing হলো একটা app-এর endpoint-গুলো client-এর request-এ কীভাবে উত্তর দেয় Source 3সোর্স 3। HTTP method-এর সাথে মেলে এমন app-এর method দিয়ে route লেখা হয়, যেমন app.get() আর app.post() Source 3সোর্স 3। একটা route path আর একটা request method মিলে একটা endpoint ঠিক করে, যেখানে request পাঠানো যায় Source 3সোর্স 3।
REST হলো distributed system-এর জন্য কিছু architecture constraint-এর সমষ্টি Source 11সোর্স 11। নতুনরা REST API বলতে ধরে নিতে পারেন এমন একটা HTTP service, যেটা সাধারণ web library আর tool দিয়ে call করা যায় Source 11সোর্স 11।
HTTP method আর status code API Testing with Postman-এ ব্যাখ্যা করা আছে। এই পেজ অন্য দিকটা দেখায়: যে server সেগুলো পাঠায়।
How it works
- Middleware. A middleware function gets the request (
req), the response (res), andnext, the next middleware function Source 4সোর্স 4. It must end the request-response cycle or callnext(); otherwise, the request is left hanging Source 4সোর্স 4. - JSON bodies.
express.json()parses requests with JSON payloads Source 5সোর্স 5. It looks only at requests whoseContent-Typeheader matches Source 5সোর্স 5. The parsed body is inreq.body, which isundefinedwhen no body parser ran Source 6সোর্স 6. - Untrusted input. Every property and value of
req.bodycomes from the user, and must be validated before you trust it Source 6সোর্স 6. - Route parameters. A route parameter, such as
:idin/orders/:id, captures a part of the URL intoreq.paramsSource 3সোর্স 3. - Unknown paths. The Hello World app of the Express guide answers every path other than
/with404 Not FoundSource 1সোর্স 1. The API of this page did the same for an unknown path in the lab. - Answers.
res.status()sets the HTTP status Source 7সোর্স 7, andres.json()sends a value as a JSON response Source 7সোর্স 7. - Login. The
Authorizationrequest header carries the credentials that give access to protected resources Source 10সোর্স 10.req.get()reads a request header Source 6সোর্স 6. - Errors. Express catches an error that synchronous code throws Source 8সোর্স 8. Handlers that return a promise call
next(value)when they reject or throw, and async functions always return a promise, so their errors reach Express with no extra work Source 8সোর্স 8. An error handler is middleware with four arguments:(err, req, res, next)Source 8সোর্স 8.
সহজ English
- Middleware. A middleware function sees the request, the response, and
nextSource 4সোর্স 4. It must answer, or callnext()to pass the request on. If it does neither, the request just hangs Source 4সোর্স 4. - JSON bodies.
express.json()reads JSON bodies Source 5সোর্স 5, but only for requests whoseContent-Typeheader matches Source 5সোর্স 5. The result is inreq.bodySource 6সোর্স 6. - Never trust the body. Everything in
req.bodycomes from the user, so check it first Source 6সোর্স 6. - Route parameters. In
/orders/:id, the:idpart of the URL lands inreq.paramsSource 3সোর্স 3. - Unknown paths. In the Express Hello World app, every path other than
/gets404 Not FoundSource 1সোর্স 1. This page's API did the same in the lab. - Answers.
res.status()sets the status code Source 7সোর্স 7, andres.json()sends JSON Source 7সোর্স 7. - Login. The
Authorizationheader carries the login details Source 10সোর্স 10.req.get()reads a header Source 6সোর্স 6. - Errors. Express catches errors in normal code Source 8সোর্স 8, and in async functions too Source 8সোর্স 8. An error handler takes four arguments:
(err, req, res, next)Source 8সোর্স 8.
বাংলা ব্যাখ্যা
- Middleware। একটা middleware function request (
req), response (res) আর পরের middleware functionnextপায় Source 4সোর্স 4। হয় এটাকে request-response cycle শেষ করতে হবে, নয়তোnext()call করতে হবে; না হলে request ঝুলে থাকে Source 4সোর্স 4। - JSON body।
express.json()JSON payload-সহ request parse করে Source 5সোর্স 5। এটা শুধু সেই request দেখে, যারContent-Typeheader মেলে Source 5সোর্স 5। Parse করা body থাকেreq.body-তে, আর কোনো body parser না চললে এটাundefinedSource 6সোর্স 6। - অবিশ্বস্ত input।
req.body-এর প্রতিটা property আর value user-এর কাছ থেকে আসে, তাই বিশ্বাস করার আগে validate করতে হবে Source 6সোর্স 6। - Route parameter।
/orders/:id-এর:id-এর মতো route parameter URL-এর একটা অংশreq.params-এ তুলে নেয় Source 3সোর্স 3। - অজানা path। Express-এর Hello World app
/ছাড়া অন্য প্রতিটা path-এ404 Not Foundদেয় Source 1সোর্স 1। Lab-এ এই পেজের API-ও অজানা path-এ তাই দিয়েছে। - উত্তর।
res.status()HTTP status ঠিক করে Source 7সোর্স 7, আরres.json()একটা value JSON response হিসেবে পাঠায় Source 7সোর্স 7। - Login।
Authorizationrequest header সেই credential বহন করে, যেটা protected resource-এ access দেয় Source 10সোর্স 10।req.get()একটা request header পড়ে Source 6সোর্স 6। - Error। Synchronous কোড error throw করলে Express সেটা ধরে Source 8সোর্স 8। যে handler promise ফেরত দেয়, সেটা reject বা throw করলে নিজে থেকেই
next(value)call করে, আর async function সবসময় promise ফেরত দেয়, তাই তাদের error বাড়তি কিছু ছাড়াই Express-এর কাছে পৌঁছায় Source 8সোর্স 8। Error handler হলো চারটা argument-এর middleware:(err, req, res, next)Source 8সোর্স 8।
Try it
Make a folder and run npm init. RETURN accepts the default for most of its questions; at the entry point, type a file name, or press RETURN to keep index.js Source 2সোর্স 2. Install Express with npm install express Source 2সোর্স 2. Save the API as app.mjs:
import express from 'express';
const USERS = [{ email: 'asha@example.com', password: 'secret123', token: 'token-asha' }];
const orders = [];
export const app = express();
app.use(express.json());
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
app.post('/login', (req, res) => {
const { email, password } = req.body ?? {};
const user = USERS.find((u) => u.email === email && u.password === password);
if (!user) return res.status(401).json({ error: 'Wrong email or password' });
res.json({ token: user.token });
});
function requireLogin(req, res, next) {
const token = req.get('Authorization')?.replace('Bearer ', '');
if (!USERS.some((u) => u.token === token)) {
return res.status(401).json({ error: 'Log in first' });
}
next();
}
app.post('/orders', requireLogin, (req, res) => {
const total = req.body?.total;
if (typeof total !== 'number' || total <= 0) {
return res.status(400).json({ error: 'total must be a positive number' });
}
const order = { id: orders.length + 1, total };
orders.push(order);
res.status(201).json(order);
});
app.get('/orders/:id', requireLogin, (req, res) => {
const order = orders.find((o) => o.id === Number(req.params.id));
if (!order) return res.status(404).json({ error: 'Order not found' });
res.json(order);
});
app.use((err, req, res, next) => {
const status = err.status ?? 500;
res.status(status).json({ error: status === 500 ? 'Something went wrong' : err.message });
});The users are a fixed list, to keep the example short. A real API stores hashed passwords in a database and issues real tokens. To start the API, save this as server.mjs and run node server.mjs:
import { app } from './app.mjs';
const port = process.env.PORT ?? 3000;
app.listen(port, () => {
console.log(`API on http://localhost:${port}`);
});Now test it. Save this as app.test.mjs and run node --test:
import test, { before, after } from 'node:test';
import assert from 'node:assert/strict';
import { app } from './app.mjs';
let server;
let base;
before(async () => {
server = app.listen(0);
await new Promise((resolve) => server.once('listening', resolve));
base = `http://localhost:${server.address().port}`;
});
after(() => server.close());
function post(path, body, token) {
const headers = { 'Content-Type': 'application/json' };
if (token) headers.Authorization = `Bearer ${token}`;
const data = typeof body === 'string' ? body : JSON.stringify(body);
return fetch(`${base}${path}`, { method: 'POST', headers, body: data });
}
test('a wrong password gets 401', async () => {
const res = await post('/login', { email: 'asha@example.com', password: 'nope' });
assert.equal(res.status, 401);
});
test('an order needs a login', async () => {
const res = await post('/orders', { total: 500 });
assert.equal(res.status, 401);
});
test('a valid order gets 201, and a bad total gets 400', async () => {
const login = await post('/login', { email: 'asha@example.com', password: 'secret123' });
const { token } = await login.json();
assert.equal((await post('/orders', { total: 500 }, token)).status, 201);
assert.equal((await post('/orders', { total: -5 }, token)).status, 400);
});
test('broken JSON gets 400, not 500', async () => {
const res = await post('/login', '{"email": "asha@example.com"');
assert.equal(res.status, 400);
});The before hook runs before the tests, and after runs after them Source 14সোর্স 14. Port 0 makes the operating system assign an unused port, which server.address().port returns Source 13সোর্স 13, so the test gets a port that is not in use. All four tests pass.
সহজ English
Make a folder and run npm init. Press RETURN to take the default for most of its questions; at the entry point, RETURN keeps index.js Source 2সোর্স 2. Then run npm install express Source 2সোর্স 2. Save the API as app.mjs:
import express from 'express';
const USERS = [{ email: 'asha@example.com', password: 'secret123', token: 'token-asha' }];
const orders = [];
export const app = express();
app.use(express.json());
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
app.post('/login', (req, res) => {
const { email, password } = req.body ?? {};
const user = USERS.find((u) => u.email === email && u.password === password);
if (!user) return res.status(401).json({ error: 'Wrong email or password' });
res.json({ token: user.token });
});
function requireLogin(req, res, next) {
const token = req.get('Authorization')?.replace('Bearer ', '');
if (!USERS.some((u) => u.token === token)) {
return res.status(401).json({ error: 'Log in first' });
}
next();
}
app.post('/orders', requireLogin, (req, res) => {
const total = req.body?.total;
if (typeof total !== 'number' || total <= 0) {
return res.status(400).json({ error: 'total must be a positive number' });
}
const order = { id: orders.length + 1, total };
orders.push(order);
res.status(201).json(order);
});
app.get('/orders/:id', requireLogin, (req, res) => {
const order = orders.find((o) => o.id === Number(req.params.id));
if (!order) return res.status(404).json({ error: 'Order not found' });
res.json(order);
});
app.use((err, req, res, next) => {
const status = err.status ?? 500;
res.status(status).json({ error: status === 500 ? 'Something went wrong' : err.message });
});The users are a fixed list to keep it short. A real API keeps hashed passwords in a database. To start it, save this as server.mjs and run node server.mjs:
import { app } from './app.mjs';
const port = process.env.PORT ?? 3000;
app.listen(port, () => {
console.log(`API on http://localhost:${port}`);
});Now test it. Save this as app.test.mjs and run node --test:
import test, { before, after } from 'node:test';
import assert from 'node:assert/strict';
import { app } from './app.mjs';
let server;
let base;
before(async () => {
server = app.listen(0);
await new Promise((resolve) => server.once('listening', resolve));
base = `http://localhost:${server.address().port}`;
});
after(() => server.close());
function post(path, body, token) {
const headers = { 'Content-Type': 'application/json' };
if (token) headers.Authorization = `Bearer ${token}`;
const data = typeof body === 'string' ? body : JSON.stringify(body);
return fetch(`${base}${path}`, { method: 'POST', headers, body: data });
}
test('a wrong password gets 401', async () => {
const res = await post('/login', { email: 'asha@example.com', password: 'nope' });
assert.equal(res.status, 401);
});
test('an order needs a login', async () => {
const res = await post('/orders', { total: 500 });
assert.equal(res.status, 401);
});
test('a valid order gets 201, and a bad total gets 400', async () => {
const login = await post('/login', { email: 'asha@example.com', password: 'secret123' });
const { token } = await login.json();
assert.equal((await post('/orders', { total: 500 }, token)).status, 201);
assert.equal((await post('/orders', { total: -5 }, token)).status, 400);
});
test('broken JSON gets 400, not 500', async () => {
const res = await post('/login', '{"email": "asha@example.com"');
assert.equal(res.status, 400);
});before runs first and after runs last Source 14সোর্স 14. Port 0 lets the operating system pick an unused port Source 13সোর্স 13, so the test gets a port that is not in use. All four tests pass.
বাংলা ব্যাখ্যা
একটা ফোল্ডার বানিয়ে npm init চালান। বেশিরভাগ প্রশ্নে ডিফল্ট মেনে নিতে RETURN চাপুন; entry point-এ একটা file নাম লিখুন, বা RETURN চেপে index.js রাখুন Source 2সোর্স 2। তারপর npm install express দিয়ে Express install করুন Source 2সোর্স 2। API-টা app.mjs নামে সেভ করুন:
import express from 'express';
const USERS = [{ email: 'asha@example.com', password: 'secret123', token: 'token-asha' }];
const orders = [];
export const app = express();
app.use(express.json());
app.get('/health', (req, res) => {
res.json({ status: 'ok' });
});
app.post('/login', (req, res) => {
const { email, password } = req.body ?? {};
const user = USERS.find((u) => u.email === email && u.password === password);
if (!user) return res.status(401).json({ error: 'Wrong email or password' });
res.json({ token: user.token });
});
function requireLogin(req, res, next) {
const token = req.get('Authorization')?.replace('Bearer ', '');
if (!USERS.some((u) => u.token === token)) {
return res.status(401).json({ error: 'Log in first' });
}
next();
}
app.post('/orders', requireLogin, (req, res) => {
const total = req.body?.total;
if (typeof total !== 'number' || total <= 0) {
return res.status(400).json({ error: 'total must be a positive number' });
}
const order = { id: orders.length + 1, total };
orders.push(order);
res.status(201).json(order);
});
app.get('/orders/:id', requireLogin, (req, res) => {
const order = orders.find((o) => o.id === Number(req.params.id));
if (!order) return res.status(404).json({ error: 'Order not found' });
res.json(order);
});
app.use((err, req, res, next) => {
const status = err.status ?? 500;
res.status(status).json({ error: status === 500 ? 'Something went wrong' : err.message });
});উদাহরণ ছোট রাখতে user-রা একটা স্থির list। আসল API hash করা password database-এ রাখে আর আসল token দেয়। API চালু করতে এটা server.mjs নামে সেভ করে node server.mjs চালান:
import { app } from './app.mjs';
const port = process.env.PORT ?? 3000;
app.listen(port, () => {
console.log(`API on http://localhost:${port}`);
});এবার টেস্ট করুন। এটা app.test.mjs নামে সেভ করে node --test চালান:
import test, { before, after } from 'node:test';
import assert from 'node:assert/strict';
import { app } from './app.mjs';
let server;
let base;
before(async () => {
server = app.listen(0);
await new Promise((resolve) => server.once('listening', resolve));
base = `http://localhost:${server.address().port}`;
});
after(() => server.close());
function post(path, body, token) {
const headers = { 'Content-Type': 'application/json' };
if (token) headers.Authorization = `Bearer ${token}`;
const data = typeof body === 'string' ? body : JSON.stringify(body);
return fetch(`${base}${path}`, { method: 'POST', headers, body: data });
}
test('a wrong password gets 401', async () => {
const res = await post('/login', { email: 'asha@example.com', password: 'nope' });
assert.equal(res.status, 401);
});
test('an order needs a login', async () => {
const res = await post('/orders', { total: 500 });
assert.equal(res.status, 401);
});
test('a valid order gets 201, and a bad total gets 400', async () => {
const login = await post('/login', { email: 'asha@example.com', password: 'secret123' });
const { token } = await login.json();
assert.equal((await post('/orders', { total: 500 }, token)).status, 201);
assert.equal((await post('/orders', { total: -5 }, token)).status, 400);
});
test('broken JSON gets 400, not 500', async () => {
const res = await post('/login', '{"email": "asha@example.com"');
assert.equal(res.status, 400);
});before hook টেস্টগুলোর আগে চলে, আর after চলে পরে Source 14সোর্স 14। Port 0 দিলে operating system একটা অব্যবহৃত port দেয়, যেটা server.address().port ফেরত দেয় Source 13সোর্স 13, তাই টেস্ট এমন একটা port পায়, যেটা কেউ ব্যবহার করছে না। চারটা টেস্টই pass করে।
How a tester uses it
- One test per status code. A good API answers each case with its own code:
201for a created resource Source 12সোর্স 12,400for a client error Source 12সোর্স 12, and401when the client must authenticate Source 12সোর্স 12. The tests above check each of them. - Attack the body.
req.bodyis user-controlled input Source 6সোর্স 6. Send a missing field, a string where a number belongs, a negative number, and broken JSON. The tests send-5and broken JSON. - Look for leaked stack traces. The built-in error handler writes the stack trace to the client, except in the production environment Source 8সোর্স 8. Send a broken body to a staging server and read the answer: it should not name files or libraries.
- Check the security basics. Helmet is middleware that sets security-related response headers Source 9সোর্স 9, and login endpoints should be protected against brute-force attempts Source 9সোর্স 9. Ask whether both are in place, and test the second with many wrong passwords.
- Run the real app in tests. Start the app on port
0Source 13সোর্স 13 in abeforehook Source 14সোর্স 14, and send real HTTP requests. The same checks can then move to API Automation with Playwright.
সহজ English
- One test per status code.
201means created,400means the request was wrong, and401means "log in first" Source 12সোর্স 12. Test each one. - Attack the body. The body comes from the user Source 6সোর্স 6. Send missing fields, wrong types, negative numbers, and broken JSON.
- Look for leaked stack traces. Express's built-in error page shows the stack trace, except in production Source 8সোর্স 8. Send a broken body and check that the answer names no files.
- Check the security basics. Helmet sets security headers Source 9সোর্স 9, and the login should resist password guessing Source 9সোর্স 9.
- Run the real app in tests. Start it on port
0Source 13সোর্স 13 in abeforehook Source 14সোর্স 14, and send real requests. Later, move the checks to API Automation with Playwright.
বাংলা ব্যাখ্যা
- প্রতিটা status code-এর জন্য একটা টেস্ট। ভালো API প্রতিটা ক্ষেত্রে নিজস্ব code দিয়ে উত্তর দেয়: নতুন resource তৈরি হলে
201Source 12সোর্স 12, client-এর ভুলে400Source 12সোর্স 12, আর client-কে পরিচয় প্রমাণ করতে হলে401Source 12সোর্স 12। ওপরের টেস্টগুলো প্রতিটাই চেক করে। - Body-কে আক্রমণ করুন।
req.bodyuser-এর নিয়ন্ত্রণে থাকা input Source 6সোর্স 6। Field বাদ দিয়ে, number-এর জায়গায় string, negative number আর ভাঙা JSON পাঠান। ওপরের টেস্ট-5আর ভাঙা JSON পাঠায়। - ফাঁস হওয়া stack trace খুঁজুন। Built-in error handler client-কে stack trace লিখে পাঠায়, শুধু production environment ছাড়া Source 8সোর্স 8। Staging server-এ ভাঙা body পাঠিয়ে উত্তর পড়ুন: তাতে কোনো file বা library-র নাম থাকা উচিত নয়।
- নিরাপত্তার মৌলিক বিষয় চেক করুন। Helmet একটা middleware, যেটা নিরাপত্তা-সংক্রান্ত response header বসায় Source 9সোর্স 9, আর login endpoint-কে brute-force চেষ্টা থেকে রক্ষা করা উচিত Source 9সোর্স 9। দুটোই আছে কি না জিজ্ঞেস করুন, আর দ্বিতীয়টা অনেকগুলো ভুল password দিয়ে টেস্ট করুন।
- টেস্টে আসল app চালান। একটা
beforehook-এ Source 14সোর্স 14 app-টা port0-তে চালু করুন Source 13সোর্স 13, আর আসল HTTP request পাঠান। তারপর একই চেক API Automation with Playwright-এ নেওয়া যায়।
Common mistakes
- A middleware that never calls
next(). If it does not end the cycle and does not callnext(), the request is left hanging Source 4সোর্স 4. - No body parser. Without
express.json(),req.bodyisundefinedSource 6সোর্স 6. The same happens when the client sends the wrongContent-Type, because the parser looks only at matching requests Source 5সোর্স 5. - Trusting
req.body. Its properties and values are untrusted until they are validated Source 6সোর্স 6. A total of'500'or-5must get400, not an order. - Stack traces in production. Without
NODE_ENV=production, the built-in error handler sends the stack trace to the client Source 8সোর্স 8. - A test on a fixed port. The port may already be in use. Port
0lets the operating system assign an unused one Source 13সোর্স 13.
সহজ English
- A middleware that never calls
next(). If it does not end the cycle either, the request just hangs Source 4সোর্স 4. - No body parser. Without
express.json(),req.bodyisundefinedSource 6সোর্স 6. A wrongContent-Typedoes the same Source 5সোর্স 5. - Trusting the body. Check every value first Source 6সোর্স 6. A total of
'500'or-5must get400. - Stack traces in production. Without
NODE_ENV=production, the error page shows the stack trace Source 8সোর্স 8. - A fixed port in tests. The port may already be taken. With port
0, the operating system picks an unused one Source 13সোর্স 13.
বাংলা ব্যাখ্যা
- যে middleware কখনো
next()call করে না। এটা cycle শেষ না করলে আরnext()call না করলে request ঝুলে থাকে Source 4সোর্স 4। - Body parser নেই।
express.json()ছাড়াreq.bodyথাকেundefinedSource 6সোর্স 6। Client ভুলContent-Typeপাঠালেও একই ঘটে, কারণ parser শুধু মেলে এমন request দেখে Source 5সোর্স 5। req.body-কে বিশ্বাস করা। Validate না করা পর্যন্ত এর property আর value অবিশ্বস্ত Source 6সোর্স 6।'500'বা-5total-এর উত্তর হতে হবে400, কোনো order নয়।- Production-এ stack trace।
NODE_ENV=productionছাড়া built-in error handler client-কে stack trace পাঠায় Source 8সোর্স 8। - টেস্টে স্থির port। Port-টা হয়তো আগে থেকেই ব্যবহার হচ্ছে। Port
0দিলে operating system একটা অব্যবহৃত port দেয় Source 13সোর্স 13।
What a tester can check
Tutorial advice
This list is the tutorial's own advice, not a fact from a source.
- Status codes. Does every route answer each case with the right code, and does each code have a test?
- Validation. Is every field of every body checked for presence, type, and range?
- Auth. Does every protected route reject a missing token, a wrong token, and a token of another user?
- Errors. Do error answers use the same JSON shape, with no stack trace and no internal names?
- Hanging requests. Does every request end, even on an error, within a time limit?
- Data. After a
201, can the new resource be read back with the same values?
সহজ English
Tutorial advice
This list is the tutorial's own advice, not a fact from a source.
- Status codes. Does each case get the right code, and is there a test for it?
- Validation. Is every field checked for presence, type, and range?
- Login. Do protected routes refuse no token, a wrong token, and another user's token?
- Errors. Do errors look the same, with no stack trace?
- Hanging. Does every request end in time, even on an error?
- Data. After a
201, can you read the new item back?
বাংলা ব্যাখ্যা
Tutorial advice
এই তালিকা টিউটোরিয়ালের নিজের পরামর্শ, কোনো source থেকে নেওয়া তথ্য নয়।
- Status code। প্রতিটা route কি প্রতিটা ক্ষেত্রে ঠিক code দিয়ে উত্তর দেয়, আর প্রতিটা code-এর কি একটা টেস্ট আছে?
- Validation। প্রতিটা body-র প্রতিটা field কি উপস্থিতি, type আর সীমার জন্য চেক করা হয়?
- Auth। প্রতিটা protected route কি token না থাকা, ভুল token আর অন্য user-এর token বাতিল করে?
- Error। Error-এর উত্তর কি একই JSON আকারের, stack trace আর ভেতরের নাম ছাড়া?
- ঝুলে থাকা request। Error হলেও কি প্রতিটা request একটা সময়সীমার মধ্যে শেষ হয়?
- ডেটা।
201-এর পর নতুন resource কি একই value নিয়ে আবার পড়া যায়?
Key words
| Term | Meaning |
|---|---|
| Express | A routing and middleware web framework; it needs Node.js 18 or higher. |
| Route | A request method and a route path, which together define one endpoint, such as POST /orders. |
| Route parameter | A named part of the path, such as :id, read from req.params. |
| Middleware | A function with req, res, and next that runs during the request-response cycle. |
express.json() | The middleware that parses JSON bodies into req.body. |
res.status() / res.json() | Set the status code / send a JSON answer. |
Authorization header | The request header that carries the credentials for protected resources. |
| Error handler | Middleware with four arguments, (err, req, res, next). |
NODE_ENV=production | Production mode; the built-in error handler then hides the stack trace. |
| REST | A set of architecture constraints for distributed systems; for a beginner, a REST API is an HTTP service that standard web tools can call. |
Port 0 | Lets the operating system pick a free port. |