Skip to content
Bucklescript bindings for Node.js
Reason HTML
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.npmrc
README.md
bsconfig.json
package.json
yarn.lock

README.md

bs-node 🚧

Bucklescript bindings for Node.js

Install

yarn add @dck/bs-node

Add it to bs-dependencies in your bsconfig.json :

{
  "bs-dependencies": ["@dck/bs-node"]
}

Usage

Fs

open BsNode;

Fs.readdir("./somepath/folder", (err, files) => {
  switch (err->Js.Nullable.toOption) {
    | None => Js.log(files)
    | Some(e) => Js.log(e)
  }
});

http

open BsNode;
open Belt;

let server =
  Http.createServer((req, res) => {
    let url = req->Http.Request.url |> Js.String.split("?");
    let path = url->Array.getExn(0);

    switch (path) {
    | "/" => res->Http.Response.endString("Index")
    | "/hello" => res->Http.Response.endString("Hello")
    | _ => res->Http.Response.endString("any")
    };
  });

server->Http.listen(1337, () => Js.log("Server started"));
You can’t perform that action at this time.