StartpodDocs

Node.js + Express

Start an Express or plain Node.js server and preview it through Startpod.

Mount a project with a Node-based start script:

await startpod.mount({
  "package.json": {
    file: {
      contents: JSON.stringify({
        type: "module",
        scripts: { dev: "node server.js" },
        dependencies: { express: "^4.21.0" },
      }),
    },
  },
  "server.js": {
    file: {
      contents: `
import express from 'express';

const app = express();
app.get('/', (_request, response) => {
  response.send('<h1>Hello from Express</h1>');
});
app.listen(3000);
`,
    },
  },
})

Install and start it:

const install = await startpod.spawn("npm", ["install"])
if ((await install.exit) !== 0) throw new Error("Install failed")

await startpod.spawn("npm", ["run", "dev"])

The server binds to Startpod's virtual network. Use the emitted preview URL instead of connecting to localhost:3000 from the host page.

Try process output

The server starts automatically. Edit server.js to change the response; Startpod restarts the process and updates the preview. The terminal shows the server output.

Loading editor…

On this page