Skip to content

Instantly share code, notes, and snippets.

@tautologico
Last active December 5, 2021 19:07
Show Gist options
  • Save tautologico/bfb9cb5207d0e5d44ae418456b25f582 to your computer and use it in GitHub Desktop.
Save tautologico/bfb9cb5207d0e5d44ae418456b25f582 to your computer and use it in GitHub Desktop.
A simple Node server in ReScript
// example ported from
// "Web Development with Node and Express", 2nd edition
// by Ethan Brown
// bindings to the node API
type res
type req
type server
@module("http") external createServer : ( @uncurry (req, res) => unit ) => server = "createServer"
@send external end: (res, string) => unit = "end"
@send external writeHead: (res, int, 'a) => unit = "writeHead"
@send external listen: (server, int, @uncurry unit => unit) => unit = "listen"
// server code
let contentType = { "Content-Type": "text/plain" }
let server = createServer( (_req, res) => {
res->writeHead(200, contentType)
res->end("Hello, world!")
})
server->listen(3000, () => Js.log("server is running"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment