Comments (9)
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.
from node-persist.
are you deleting the storage folder while your application is running?
or are you killing the app, deleting the storage folder, then restarting to see the ENOENT error?
from node-persist.
Also, can you provide a full stack trace please, I just need lines numbers, feel free to obfuscate the full filepaths
from node-persist.
Thanks for the fast response!
I'm terminating node, removing the storage files and folder and then starting the application again.
Here's what I got:
// console output
d:\path\to\project\projectname\node_modules\node-persist\src\local-storage.js:36
if (err) throw err;
^
Error: ENOENT: no such file or directory, open 'd:\path\to\project\projectname\server\storage\6a99c575ab87f8c7d1ed1e52e7e349ce'
at Error (native)
//npm-debug.log
14 verbose stack Error: [email protected] dev: `npm run startInternal`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:242:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:852:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid [email protected]
I hope that's everything? Can't seem to convince node to provide any more information.
Tried debugging but can't see anything out of the ordinary
//callstack from debugging, backtracing from thrown error
noop local-storage.js 36
(anonymous function) local-storage.js 447
(anonymous function) fs.js 1305
(anonymous function) fs.js 123
I can see the folder was created successfully on the FS.
from node-persist.
can you provide the following:
• node --version
• the version of the node-persist
package you are using
• show me the block of the code that you are using to init/initSync
the storage instance.
Also, are you using some sort a master Node process to spawn and handle other Node processes? like a cluster or something? can you share what npm run startInternal
is doing? I suspect you have a multiple processes and one of them is not getting killed.
This is really weird, the test cases always delete the storage dirs with no issues, maybe there is a case we didn't cover.
I'd be happy to help but I need a little more. Is your project open source?
from node-persist.
No, it's not open source - but I will try to provide all information:
d:\path\to\project\projectname>node --version
v6.4.0
d:\path\to\project\projectname>npm -v node-persist
3.10.3
And the npm scripts
"scripts": {
"start": "npm run build && npm run startInternal",
"build": "webpack -p --config webpack.production.config.js",
"startInternal": "node -r dotenv-safe/config server"
}
//during development, app is started with 'npm run startInternal'
As well as the storage init:
// server\index.js - entry point
const storage = require("node-persist");
storage.init({
dir: "server/storage"
});
Nothing is interacting with storage in any way.
I try to recreate the problem in a different project that I can share.
from node-persist.
Here you go: https://github.com/Jan-Ka/verbose-succotash
from node-persist.
awesome! thanks for this! i will take a look tonight
from node-persist.
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);
from node-persist.
Related Issues (20)
- Create different localstorages? Like collections HOT 1
- How to use asynchronous init() HOT 4
- Upstream dependency has a vulnerability (minimist 0.0.8 from mkdirp 0.5.1) HOT 4
- EISDIR: illegal operation on a directory, read on @eadir folders, synology NAS HOT 2
- Error: EROFS: read-only file system, mkdir '/storage' HOT 4
- Improvement: Typescript Support HOT 1
- const storage = require('../node_modules/node-persist'); causes NodeJS to throw error HOT 6
- Is there a good way to manage multiple directories? HOT 1
- [Enhancement] Storage folder inside other storage folder is a bad idea HOT 5
- Can we store node event emitter objects in this? HOT 1
- Unable to write file on google function workspace 🤯 HOT 1
- Appending files / persisting logging data
- Just a Question: Version 3 "All the *Sync functions were removed, every operation is now asynchronous" HOT 1
- node-persist error sometimes makes the application to crash HOT 6
- Getting this error intermittently: 'Error: EMFILE: too many open files' HOT 2
- Can it store binary data(buffer)? HOT 2
- Version 4 not published on npm HOT 1
- Confusing README and lack of "sync" functions HOT 4
- node-persist reading all files to RAM ? HOT 4
- Filenames on Windows are case-insensitive, ie. should use base32 instead of base64 to avoid key mismatch
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-persist.