Hey ninjas, in this Node JS tutorial I’ll show you how we can create and delete directories, as well as deleting files too.

+ Repo –
+ Atom editor –

You can find more front-end development tutorials on CSS, HTML, JavaScript, jQuery, WordPress & more on the channel homepage…


========== JavaScript for Beginners Playlist ==========

============ CSS for Beginners Playlist =============

============== The Net Ninja =====================

For more front-end development tutorials & to black-belt your coding skills, head over to – or

================== Social Links ==================

Twitter – @TheNetNinja –


  1. 1:01
    // Catch file not found exception

    var fs = require('fs');

    var fileContents;
    try {
    fileContents = fs.readFileSync('writeMe.txt', 'utf8');
    } catch (err) {
    console.log('File not found :n' + err);

  2. Tell me why in this deleting file case it shows Deprecate warning that "Calling an asynchronous function without callback is deprecated"..

  3. Dear Shaun,

    Thanks for these fantastic vids, you have a fantastic channel here. Could you please shortly explain which considerations you would make when choosing between these sync and non-sync methods?


  4. So if I wanted to create the directory and then 3 seconds later remove it what can I do about the error that shows up in the command prompt after the function continues to run rmdir('stuff')?

    var fs = require('fs');

    fs.mkdir('newdir', function(){
    fs.readFile('readMe.txt', 'utf8', function(err, data){
    fs.writeFile('./newdir/writeMe.txt', data);

    fs.unlink('./newdir/writeMe.txt', function(){
    }, 3000);

    Any thoughts?

  5. what if there are multiple files in a directory and you want to remove the folder anyway and all its contents. so is there any way to do it forcefully?

  6. ** Node come up with: 'DeprecationWarning: Calling an asynchronous function without callback is deprecated.'

    The reason being that whilst the fs.readfile has a callback function, the fs.writefile does not. So if you run fs.writefileSync this still works perfectly. **

    (Could be wrong) – Thanks so much Shuan. Great series as usual :):)

  7. Hi, these are really good tutorial, I have a question, when I run the mkdir and the readFile methods I get this message in the console.

    (node:32964) DeprecationWarning: Calling an asynchronous function without callback is deprecated.

    even though I have a cb in both async methods, does writeFile should also get a cb function?

  8. hi, thank you for this awsome tutorial .

    is there a was to check if a directory is not empty inside the code??
    something like

    if(dir is not empty){
    do this;

  9. I had to remove replace ".stuff" with "stuff" in the directory path. Didn't work with the dot. Also, I don't quite understand why we do this asynchronously with the function inside unlink. We can just have


  10. Hi, Shaun. It's so pleasurable to watch and learn NodeJS through your tutorials. It's clear and informative. I do have two questions for this tutorial:

    1.) What to do (for deleting a directory) when there's a lot of files in the directory, and file name may be unknown?
    2.) How to move file(s) from one folder (directory) to another folder (directory)?

    Thank you. 🙂


Please enter your comment!
Please enter your name here