question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Deleting Storage Folder throws error on first start

See original GitHub issue

Hello,

Not sure if this is a Problem of node-persist or Node but when I delete the Storage Folder a ENOENT error is thrown on first start.

Error: ENOENT: no such file or directory, open 'd:\path\to\project\projectname\server\storage\hash'

It fixes itself if you just restart the app but It cripples my deployment script. Is there a Cache File somewhere I need to delete?

Thanks for the Help

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
akhourycommented, Nov 16, 2016

ok, so here’s what’s happening, you’re trying to setItem() before the storage has finished initializing, and creating the the storage directory, that’s why it only does it the first time, the second time the directory is already created.

When you use storage.init(), it’s asynchronous, you need to wait for it to be ready before you can use the storage

This is my fault, the example in the README was wrong, I just fixed it

you can solve this in 2 ways, either,

Wait for it to be done, before using it

storage.init().then(()=> {
    // start your app here.
});

OR

Use the synchronous version of init - this is OK if you are doing it once at app-load time, it will not really impact performance

storage.initSync();
// start your app here.
0reactions
Jan-Kacommented, Nov 16, 2016

Thank you for the quick fix - i just tested it and it works fine.

Somehow I didn’t think of testing the Problem without setting a variable 😃

Code for reference:

const storage = require("node-persist");

let storageInit = storage.init({
    dir: "server/storage"
});

const argvs = process.argv.slice(2);

if (argvs[0] === "setup") {
    console.log("INIT", "SETITEM", "WAIT 5s", "EXIT");

// here be changes
    storageInit.then(() => {
        storage.setItem("demo",
            [
                {
                    "demo": "data"
                }
            ]
        ).then(
            function () {
                console.log("SETITEM SUCCESSFULL");
            },
            function (reason) {
                console.log("SETITEM ERROR", reason);
            });
    });
} else {
    console.log("INIT", "WAIT 5s", "EXIT");
}

setTimeout(() => {
    process.exit();
}, 5000);
Read more comments on GitHub >

github_iconTop Results From Across the Web

7 Solutions to Delete a File or Folder Showing Error “Access Is ...
Here is the step by step process of deleting a file/folder that is undeletable: First, open CMD: press the start button and type...
Read more >
2021 Guide: Fix 'Unable to Delete Folders/Files from External ...
The best practice is to find out the actual cause of why the can't delete files error is triggered in the first place....
Read more >
[Solved] Unable to Delete a Folder In Windows 10 - mulcas
Solution · Option 1: Restart Windows File Explorer · Option 2: Remove the folder using Windows Command-line · Option 3: Rename the folder...
Read more >
Can't delete files on NTFS file system - Windows Server
This article describes why can't delete a file or a folder on an NTFS file system volume. It also provides help to solve...
Read more >
Fix “Could Not Find This Item” When Deleting in Windows
If you still can't delete the file and it keeps throwing the “could not find this item” error, you can try deleting the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found