Run a Node.js dev server in Stackblitz WebContainers without local setup
Run a Node.js dev server entirely in the browser with Stackblitz WebContainers. Create from a compatible template, install dependencies in the container, start the dev server from the integrated terminal, and verify hot reload and file writes. Know the limits around native modules and system access.
05 Oct 2026, 14:45 UTC

Problem: prototype a Node app without asking the team to install Node
Sharing a runnable demo usually means documenting local setup, Node version, and npm install steps. WebContainers in Stackblitz moves that work into the browser with an in-browser Node.js runtime and a local-like file system, so a reviewer can open the project and run it immediately. The useful takeaway is to use it for pure-JavaScript/TypeScript prototypes and demos, and to fall back to local development when native binaries or privileged system access are required.
Desired outcome
A project that edits, installs, and runs entirely in the browser. You get a writable file system, an integrated terminal, and a preview pane for the dev server. File changes persist for the session and npm install resolves from the container, not your machine.
Prerequisites
- A Stackblitz account. Private or team features may require a paid plan and visibility settings should be reviewed before sharing.
- A framework or library compatible with the WebContainers Node runtime. Pure JS/TS stacks such as Vite, Next.js, Express, and Svelte work well. Native Node addons and system-level binaries are not supported.
- Browser with sufficient memory for the container. Performance and stability depend on browser memory limits and network latency for dependency fetching.
WebContainers is an origin-private file system implementation that runs Node in the browser via WebAssembly. It mimics a local environment but does not provide privileged OS access.
Focused procedure
Create from a compatible template
In Stackblitz, start a new project from a template such as Vite + React or Node Express. Use a template that ships a package.json with a dev script. This avoids manual scaffolding and ensures the initial dependency graph is known to the container.
Allow the initial install to complete
On first open, Stackblitz installs dependencies inside the WebContainer. Do not start the server until the install indicator clears. The integrated terminal shows npm output.
Start the dev server from the integrated terminal
Open the integrated terminal in the Stackblitz UI. Run the dev command defined in package.json.
npm run dev
Where to run: Stackblitz integrated terminal, no elevated permissions required. Placeholder: replace dev with your script name if different, e.g., npm run start:dev.
Risk: starting the server before install finishes can cause missing module errors. If the install fails, see recovery below.
Verify hot reload
Edit a source file in the editor. The preview pane should update without manual restart if the framework supports hot module replacement. This confirms the file system is writable and the dev server is bound to the preview.
Expected checks
- Dev server URL responds in the preview pane. Open the preview and confirm the application loads and responds to requests.
- Console logs appear in both the preview console and the terminal. Logs confirm the process is running inside the container.
- File changes persist for the session. Edit a file, save, and confirm the change is visible after a page refresh within the same project.
- Package install finishes without WebContainers compatibility errors. A clean install indicates the dependency tree contains no native addons.
Practical verification commands in the integrated terminal:
ls
Where to run: integrated terminal. Expected check: directory listing reflects the project files. Risk: none. This confirms the in-browser file system is responsive.
Concrete example configuration
For a Vite React prototype, package.json typically contains:
{
"scripts": {
"dev": "vite",
"build": "vite build"
}
}
Start with npm run dev in the terminal. The preview URL is provided by Stackblitz. Do not assume a specific port; WebContainers maps the server to the preview automatically.
Limitations
WebContainers does not support native Node addons or system-level binaries. Builds requiring compilation, e.g., node-gyp modules, will fail.
No privileged system access is available. Operations that require root, Docker, or host file access are not possible.
Session state is tied to the browser tab. Closing the tab ends the container and unsaved changes may be lost.
Recovery options
If the dev server fails to start or install errors appear:
- Restart the WebContainer via the Stackblitz UI controls. This clears runtime state without changing files.
- Clear and reinstall dependencies. In the integrated terminal run
rm -rf node_modules package-lock.jsonthennpm install. Risk: network latency may cause timeouts on large trees. - Fork the project to reset state. Forking creates a fresh copy and can resolve corrupted container state.
- Fall back to local development when native modules or system tools are required. Document the incompatibility for the team.
Verification after recovery: repeat the expected checks above. Confirm the dev server loads, hot reload works, and terminal commands succeed.
Note: behavior is subject to change with Stackblitz and browser implementations. Current verification is recommended before relying on this workflow for critical demos.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.