Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Reading a file contents

$
0
0

Much like Typescript, ReScript doesn’t necessarily target node; because of this, the docs try to be agnostic as to the runtime. Instead, the bindings to node are provided as a library, available here.

The bindings library doesn’t have much documentation, but through a combination of seeing the modules that live under the top-level NodeJs module, and reading the JS node docs, we can find readFileSync, which seems to be what you’re looking for.

Since you want the string representation, the simplest way implement load with this helper would be:

let load = NodeJs.Fs.readFileSyncWith(_, {encoding: "utf8"})

or, if you prefer a more explicit representation:

let load = name => NodeJs.Fs.readFileSyncWith(name, {encoding: "utf8"})

(We use NodeJs.Fs.readFileSyncWith rather than NodeJs.Fs.readFileSync because the former allows us to provide the second options argument)


Viewing all articles
Browse latest Browse all 2592

Trending Articles