How to create Express.js server in ReasonML

Image for post
Image for post

I have created a lot of Express servers and a lot of my projects starts that way. Recently I have gotten into ReasonML and naturally I wanted to create my first express.js server and see how difficult that would be.

A pretty normal express.js server in Node.js looks like this:

First I created it like this, which worked but did not look correct!

This was after a lot of trial and error but the output was correct! Success at first glance, then we can always improve!

But the way we are running functions directly on objects is not and does not look correct. After some help and hints on the ReasonML Discord I made it look like this:

Which still produces the same output:

You can see that we are calling functions with express and response object as arguments, much cleaner but still not immutable but that can be for another topic!

This is not a full example of typing the whole express.js api, but it gives you a quick glance of how you can do it yourself.

What do you like about ReasonML and what are you learning about it?

I really like building stuff with React.js and Docker and also Meetups ❤

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store