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

How to deploy an Express app

Deploy a Node.js Express app on Schokr: listen on 0.0.0.0 and your allocated port, upload your code, set the start command and go live.

Updated · 1 min read

To deploy an Express app on Schokr, create a Node.js server, upload your code and package.json, make Express listen on 0.0.0.0 and your allocated port, and set your entry file in the Startup settings.

1. Prepare your app

A minimal production-ready index.js:

const express = require('express')
const app = express()

app.use(express.json())
app.get('/', (req, res) => res.json({ status: 'ok' }))

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

And package.json:

{
  "name": "my-express-app",
  "main": "index.js",
  "scripts": { "start": "node index.js" },
  "dependencies": { "express": "^4.21.0" }
}

2. Create the server

  1. In the console, create a server with the Node.js template.
  2. 256 to 512 MB of memory is plenty for most Express APIs.
  3. Open the Network section and note the port.

3. Upload and configure

  1. Upload index.js, package.json, package-lock.json and your other source files with the file manager. Skip node_modules.
  2. Set the port: either put it in a .env file as APP_PORT=<your-port> and load it (see environment variables), or hard-code it.
  3. In your server's Startup settings, set the main file to index.js (or the start command, depending on what the template exposes).

4. Start and test

Start the server. The console should show npm installing packages, then your "Express listening" line. Open http://<server-address>:<port> to check.

Production tips

  • Set NODE_ENV=production in your .env. Express then caches view templates and produces less verbose errors.
  • Serve static files with express.static:
app.use(express.static('public'))
  • If you put a proxy such as Cloudflare in front, tell Express to trust it so req.ip and req.protocol are correct:
app.set('trust proxy', 1)
  • Add an error handler so one bad request does not crash the process:
app.use((err, req, res, next) => {
  console.error(err)
  res.status(500).json({ error: 'Internal error' })
})
  • Handle unexpected crashes in async code with process.on('unhandledRejection', console.error) while you debug.

Data storage

There is no built-in database on Schokr. For a single-server app, SQLite works well. For larger needs, use an external database provider and keep its URL in your .env file.

Troubleshooting