Sometimes, we want to use import fs from ‘fs’ with JavaScript.
In this article, we’ll look at how to use import fs from ‘fs’ with JavaScript.
How to use import fs from ‘fs’ with JavaScript?
To use import fs from ‘fs’ with JavaScript, we’ve to run our Node.js app with Node.js 10 or later.
And the --experimental-modules
flag has to be enabled.
Once the requirements are met, then we write
import { readFileSync } from "fs";
to import the readFileSync
function from the fs
ES module.
Conclusion
To use import fs from ‘fs’ with JavaScript, we’ve to run our Node.js app with Node.js 10 or later.
And the --experimental-modules
flag has to be enabled.