javascript – Node fs.js rodando no HTML


Hello, I need to use the fs function from node.js but I am encountering errors. When I run using node use_fs.js it runs and works perfectly. However when I put it inside the html it always says q require is not defined. That is, when I run in the console it works and when I put it in the browser it doesn't work, I know that fs is a core function of node.js, but when

<script language="javascript">
          var fs = require('fs');
          var fileContent = "Hello World!";
          var filepath = '_folder/file.txt';
          fs.writeFile(filepath, fileContent, function (err) {
            if (err) throw err;

can someone give a tip?


There is a difference in running javascript in NodeJs and in Browser, in Node the platform maps the operating system's libs, whereas in the Browser it maps those of the Browser itself, so it will not be possible to use fs since it is a function mapped to the operating system.

Scroll to Top