NewSchokr 13 is here. A whole new UI, seven locations, snapshots and more. Read more →

How to host a static website with a small Node server

Serve a static HTML, React or Vite build on Schokr using a tiny Node.js or Bun server that listens on your allocated port.

Updated · 1 min read

Schokr runs processes rather than offering a static file host, so to publish an HTML site or a built React, Vue or Vite app, run a tiny web server that serves your files on 0.0.0.0 and your allocated port.

1. Build your site locally

For a plain HTML site, there is nothing to build. For frameworks:

ToolBuild commandOutput folder
Vite (React, Vue, Svelte)npm run builddist
Create React Appnpm run buildbuild
Astro (static)npm run builddist
Next.js static exportnext build with output: 'export'out

Building locally saves memory and time on the server. You only upload the output.

2. Option A: Express static server

server.js:

const express = require('express')
const path = require('path')

const app = express()
const dir = path.join(__dirname, 'dist')

app.use(express.static(dir, { maxAge: '1h' }))

// Single-page apps: send index.html for unknown routes
app.use((req, res) => res.sendFile(path.join(dir, 'index.html')))

const port = Number(process.env.APP_PORT || 3000)
app.listen(port, '0.0.0.0', () => console.log(`Serving on ${port}`))

package.json:

{
  "main": "server.js",
  "dependencies": { "express": "^4.21.0" }
}

Remove the fallback route if your site is plain multi-page HTML, so missing pages return a 404.

2. Option B: Bun with no dependencies

server.js on a Bun server:

const root = './dist'

Bun.serve({
  hostname: '0.0.0.0',
  port: Number(process.env.APP_PORT || 3000),
  async fetch(req) {
    let path = new URL(req.url).pathname
    if (path.endsWith('/')) path += 'index.html'
    if (path.includes('..')) return new Response('Bad request', { status: 400 })
    const file = Bun.file(root + path)
    if (await file.exists()) return new Response(file)
    return new Response(Bun.file(root + '/index.html'))
  },
})

3. Deploy

  1. Create a Node.js or Bun server in the console. 128 to 256 MB of memory is enough.
  2. Upload server.js, package.json (for Express) and your build folder with the file manager. Zipping the folder and extracting it on the server is fastest.
  3. Set the port, either hard-coded or via .env (see environment variables).
  4. Set the main file in your server's Startup settings and start the server.
  5. Visit http://<server-address>:<port>.

Updating the site

Rebuild locally, delete the old build folder in the file manager, upload the new one and restart. See updating your app.

Using a domain

To serve the site on your own domain, see using your own domain. Schokr has no built-in HTTPS, so a proxy service in front is the usual way to get it.