Node.js Making Directories

Kino

EIS Game Dev
Veteran
Joined
Nov 27, 2015
Messages
556
Reaction score
794
First Language
English
Primarily Uses
RMMV
Introduction
Continuing from our second post on Node.js, we're going to make directories to properly store and hold files. You might think this isn't important, but let's talk about the benefits.

The Benefits
The benefits of making directories or folders are that you can organize files and create structures for both you and the developers you're working with. File organization is important for efficiency. Now, I believe for certain plugins, creating structure is a more important benefit of being able to create directories within your plugin.

By creating structures within our directory, we can write and read the files that are important to our plugin. For example, the Rem system uses a folder structure to organize text information into categories for simple processing, rather than having to look through extra files.

The Setup
We'll be using the plugin from our first tutorial and extending it to support creating directories; you can copy it below.


Now, let's declare our makeDirectory method in our FS class, which uses the "fs" module in Node.js


This method takes a relative path (the root of your directory) and creates a directory from that point. To make sure we don't overwrite any directories, we're going to add a simple check. In the next section, we'll be adding to our implementation with this in mind. Now, let's define our makeDirectory method.


Here we define makeDirectory and add a method from the "fs" module to check if the directory exists called existsSync. This is to be certain our directory is safe to be created. Next, we make the actual directory using the mkdirSync method in the "fs" module. The directory is then created using standard system calls on your operating system.

Here's what it looks like in-game:





Now, I wouldn't use it like this myself, but it'd be great to setup the folder structure for your plugin without asking users to create the folder themselves. This makes your life and their lives easier since there's less of a chance for error with using the plugin.

Anyway, I hope this post was helpful to all and stay tuned for more posts in the future!
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,085
Members
137,583
Latest member
write2dgray
Top