# Express server

> A real npm install of Express from the registry, then its server, which restarts as you edit server.js.

Live: https://clientvm.joeldsouza.me/demos/express/ (Chromium) · Source: https://github.com/Reflex-Gravity/client-vm/blob/main/site/src/demos/express.ts

The instance starts with a package.json and a server.js, nothing else. The unmodified npm that Node 24 bundles installs Express and its dependencies from the registry, into the instance’s own filesystem.

When server.js listens on port 3000, a service worker on the instance’s origin serves the page to the preview. Edit server.js in the editor and the demo restarts the server for you.

## How it's built

```ts
const app = await vm.createInstance({
  fs: { from: { home: { user: { app: { 'package.json': pkg, 'server.js': server } } } } },
});

app.onPortOpen((port, url) => (preview.src = url));
await app.exec('npm install && npm start', { cwd: '/home/user/app' });
```

## Try

- count packages: `ls node_modules | wc -l`
- express version: `node -p "'express ' + require('express/package.json').version"`
- add a package: `npm install ms && node -p "require('ms')('2 days')"`
- git commit: `git init -q && git add . && git commit -qm init && git log --oneline`
- start server: `npm start`

## Built with

npm 11, Express 4, Node.js 24

## Docs

- [npm in ClientVM](https://clientvm.joeldsouza.me/docs/decisions/0012-npm-on-first-use/)
- [Previews](https://clientvm.joeldsouza.me/docs/decisions/0008-sub-origin-per-port/)
