Running a Full‑Stack Express API in StackBlitz with WebContainers
Learn how to run a full Express API inside StackBlitz using WebContainers, see the steps to set it up, and understand the limits of in‑browser Node.js.
12 Sept 2026, 10:15 UTC

Problem: Waiting for a backend to start
When you want to experiment with a Node.js API, the usual flow involves cloning a repo, running npm install, starting a server, and then opening a browser to see the result. Each step adds latency, and you need a remote sandbox or a local machine with the right tooling.
Thesis: StackBlitz’s WebContainers let you run a full Node.js environment entirely in the browser
WebContainers compile the Node.js runtime and its core modules to WebAssembly, so npm install, script execution, and a listening server all happen inside the tab. Because the environment is client‑side, the project starts instantly, works offline after the initial load, and avoids the cost of a remote sandbox.
Setting up an Express server in StackBlitz
- Open StackBlitz and choose the Node.js template.
- In the file explorer, add a new file named
server.jswith the following content:
const express = require('express');
const app = express();
const PORT = 3000;
app.get('/api/hello', (req, res) => {
res.json({ message: 'Hello from StackBlitz!' });
});
app.listen(PORT, () => {
console.log(`Server listening on http://localhost:${PORT}`);
});
- Add Express to the project by opening the terminal (bottom panel) and running:
npm install express
No special permissions are required; the terminal runs with the same privileges as the editor.
- Start the server:
npm start
Assuming package.json contains a start script like "start": "node server.js", the command launches the Express process inside the WebContainer.
Live preview and hot‑module replacement
Once the server is running, open the Preview pane. Navigate to http://localhost:3000/api/hello (or click the link that appears in the terminal). The pane proxies the request to the in‑browser server and displays the JSON response. Because the frontend code is served by StackBlitz’s static file server, any changes to client‑side files trigger hot‑module replacement without restarting the backend, giving a seamless edit‑refresh loop for full‑stack work.
Trade‑offs and limitations
| Limitation | Why it matters | How to check |
|---|---|---|
| Native addons | Packages that rely on OS‑specific binaries (e.g., bcrypt, sharp) cannot be compiled to WebAssembly and will fail during npm install. | After adding such a package, watch the terminal for errors mentioning "preinstall" or "build failed". If the install succeeds, the package likely does not need native code. |
| Memory and CPU constraints | The WebContainer shares the browser tab’s resources; large monorepos or heavyweight servers can cause slowdowns, high CPU usage, or tab crashes. | Open the browser’s task manager (Shift+Esc in Chrome) while the preview is open. If the JavaScript memory steadily grows beyond ~500 MB or CPU stays near 100 %, consider scaling back the project size. |
| Limited filesystem access | Only the virtual file system exposed by StackBlitz is available; direct access to the host OS is not possible. | Try to read a file outside the project with require('fs').readFileSync('/etc/passwd'). The operation will throw an error, confirming the sandbox boundary. |
Actionable closing
If you need an instant, shareable full‑stack preview—especially for demos, interviews, or learning—StackBlitz’s WebContainers give you a zero‑setup Node.js backend that runs in the browser. Start with the Express example above, verify the API responds in the preview pane, and then iterate on your frontend code while the server stays alive. Keep an eye on the browser’s resource monitor to stay within the memory limits, and avoid packages that require native binaries. For heavier workloads, consider a traditional local dev environment or a remote sandbox, but for many everyday tasks the in‑browser approach saves time and eliminates external dependencies.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.