Skip to main content
Prerequisites:
  • A recent version of Node.js (22 or higher)
  • A package manager like npm, pnpm or yarn
1

Setup DNS Records

Before we can start with any code, we need to ensure that the application’s domain is pointing to the server.To do this, go to your cloud provider’s dashboard and find the IP address of the machine that will run your application. Then, from your DNS provider’s dashboard, create an “A” record with the value set to the IP address of the server.
2

Install MagicServer

  • npm
  • pnpm
  • bun
  • yarn
npm install @magicserver/magicserver
3

Replace you usage of `createServer` with `createMagicServer`

server.js
import { createServer } from "node:http"
import { createMagicServer } from "@magicserver/magicserver"

function app(req, res) {
  res.end("Hello, World!")
}

const server = createServer(app);  
const server = createMagicServer("your-domain.com", app);  

server.listen(80) 
Notice that we also removed the server.listen() call. We do this because MagicServer will automatically listen on port 443, which is the port for HTTPS.
4

Start the server

Now whenever your application is started, it will be automatically served over HTTPS and stay up to date with certificates without needing any intervention.
node server.js

Curious about how it works?

It’s not a sleight of hand! Learn the magic behind MagicServer.
I