What is require('fs')?

There's this piece of code in StorageManager

Code:
StorageManager.saveToLocalFile = function(savefileId, json) {    var data = LZString.compressToBase64(json);    var fs = require('fs');    var dirPath = this.localFileDirectoryPath();    var filePath = this.localFilePath(savefileId);    if (!fs.existsSync(dirPath)) {        fs.mkdirSync(dirPath);    }    fs.writeFileSync(filePath, data);};
What is the require syntax? Where is "fs" defined?
'fs' is part Node.JS. It's the FileSystem. It's used on the desktop clients to read and write data onto the hard drive. Since this only works for the local clients only, there are checks to make sure we're running on the local version before trying to write files. 

As for documentation, you'll have to look at Node's docs on it, since they're the ones that provide the functionality.
Zalerinian answered the FS part, so as far as "require" - here's the most helpful thing I found from some searching:

require() is not part of your standard JavaScript. In context to your question and tags, require() is built into Node.js to load modules. The concept is similar to C/Java/Python/[insert more languages here] imports or includes.
'fs' is part Node.JS. It's the FileSystem. It's used on the desktop clients to read and write data onto the hard drive. Since this only works for the local clients only, there are checks to make sure we're running on the local version before trying to write files. 


As for documentation, you'll have to look at Node's docs on it, since they're the ones that provide the functionality.
I don't remember seeing node.js in my project folders.


Are they pulling it in from somewhere else?
I don't remember seeing node.js in my project folders.

Are they pulling it in from somewhere else?
The node files aren't brought out until you export it as windows or mac. To test play it, MV just kinda launches the node client and tells it to look at your project folder for the source (I'm assuming here). You can find the executable stuff in the nwjs-win and nwjs-osx folders. nwjs is just an extension for node that adds a striped-down verison of Chrome 41 onto it, as I understand it.
The node files aren't brought out until you export it as windows or mac. To test play it, MV just kinda launches the node client and tells it to look at your project folder for the source (I'm assuming here). You can find the executable stuff in the nwjs-win and nwjs-osx folders. nwjs is just an extension for node that adds a striped-down verison of Chrome 41 onto it, as I understand it.
oh, I think I get it.


This means that if I wanted to, for example, allow players to save a picture from the game, I would need to handle things depending on whether they're in a browser or running locally just like the save files.
oh, I think I get it.

This means that if I wanted to, for example, allow players to save a picture from the game, I would need to handle things depending on whether they're in a browser or running locally just like the save files.
That is correct. Because if they're on the web browser, you don't have access to their hard drive, and this can't save the file directly for them. You'd need to display it in a way that they can save it, whether it be on a canvas tag (you can right-click and save image as. At least in chrome), or by finding a magical way to display a bitmap in an img tag that the user can right click and save.
My code uses require statements every where to make things more modular and clean. I then use broswerify and babelify to compile it down into some really ugly code but, it all works 😀

Original thread: https://forums.rpgmakerweb.com/threads/what-is-require-fs.49547/