Last active
December 5, 2021 19:07
-
-
Save tautologico/bfb9cb5207d0e5d44ae418456b25f582 to your computer and use it in GitHub Desktop.
A simple Node server in ReScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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