Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: ENOENT: no such file or directory, rename 'path/file.js~' -> 'path/file.js' (while using nodemon) #462

Open
rafaelferreiraql opened this issue Oct 20, 2016 · 12 comments

Comments

@rafaelferreiraql
Copy link

Now, I don't know if it's nodemon or nedb's fault, but sometimes I have to restart nodemon a couple times because this error comes up... Not a huge deal, but still annoying. Please note that I'm also using the --ignore flag so the file.js~ automatic refresh doesn't infinitely loop with nodemon's own automatic refresh, idk if this has something to do with my issue.

@fpassa
Copy link

fpassa commented Jan 31, 2017

What's the file path expected when is compiled into an executable file. For instance, in macOS my project works fine when running it with npm start

But, after packaging it with electron-package and attempting to execute it, the error appears by stating that Uncaught Error: ENOENT: no such file or directory, open filename - datastore.js:77

Where is supposed to be located the db file after application is packaged? Have this been tested (the NeDB) on compiled apps? If so, what's the path to use?

@chenyuansgit
Copy link

i have the same problem, when the error is happen, the content of the data file is clear, how to deal it?

@zearg
Copy link

zearg commented Jun 28, 2017

up, i have the same problem when electron app is in an ASAR package

@zergius-eggstream
Copy link

I met the same problem, but i found that error appears when creating multiple instances of datastore with same filename. You have to instantialize datastore only once and keep reference across whole app. May be developers should provide singleton/factory (for example var db = require('nedb').open({filename: 'path/to/file'}) ) instead of creating instances

@heyuncoder
Copy link

when i use var db = require('nedb').open({filename: 'path/to/file'}) ) ,
i get an error: require(...).open is not a function

@gabrielmicko
Copy link

I have the same issue in tests... .open is not defined. I can't find any workaround so far.

@JamesMGreene
Copy link
Contributor

We don’t need a new API to have singletons, just abstract it with a local module of your own, e.g.

db.js:

const Datastore = require('nedb');

const db = {
  tableName: new Datastore({ filename: '...' })
};
module.exports = db;

@thrazu
Copy link

thrazu commented Nov 22, 2019

Check if you are trying to open two or more connections at once. In my case I'm opening two connections and get the error.

@xeroxstar
Copy link

xeroxstar commented Jan 28, 2020

Check if you are trying to open two or more connections at once. In my case I'm opening two connections and get the error.

How can we open two or more connections at once? I have this code that give me same error:

let collections = {
    users   : __dirname + '/db/bundles/users',
    scripts : __dirname + '/db/bundles/scripts'
};

for(let i in collections){
        collections[i] = new nedb({
            filename : collections[i],
            autoload : true
        })
}

@thrazu
Copy link

thrazu commented Jan 28, 2020

@xeroxstar your code tries to open multiple databases (files). What if you have just one file, let's say db.json and multiple 'tables': users, scripts etc. Try something like this:

import Datastore from 'nedb';
...
const db = new Datastore({ filename: '/db.json', autoload: true });

db.insert({ table: 'users', ...userdata }, (err) => {
    ...
})
db.insert({ table: 'scripts', ...scriptdata }, (err) => {
    ...
})

...
let collections = {
  users: [],
  scripts: []
};

db.find({ table: 'users' }, function (err, users) {
    // get all users
    // If no document is found, users is equal to []
   collections.users = users
});

This code wasn't tested.

@xeroxstar
Copy link

xeroxstar commented Jan 28, 2020

@xeroxstar your code tries to open multiple databases (files). What if you have just one file, let's say db.json and multiple 'tables': users, scripts etc. Try something like this:

import Datastore from 'nedb';
...
const db = new Datastore({ filename: '/db.json', autoload: true });

db.insert({ table: 'users', ...userdata }, (err) => {
    ...
})
db.insert({ table: 'scripts', ...scriptdata }, (err) => {
    ...
})

...
let collections = {
  users: [],
  scripts: []
};

db.find({ table: 'users' }, function (err, users) {
    // get all users
    // If no document is found, users is equal to []
   collections.users = users
});

This code wasn't tested.

thank for reply, yes you right, i guess i will do it if there is no solution to solve what i am trying to achieve...

@siarhei-klimuts
Copy link

I am using next.js api routes, and in development mode there a lot of HMR reloads, so extracting db to a module does not help, nothing helps so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests