Categories
JavaScript Answers

How to use import fs from ‘fs’ with JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *