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

new LocalStorage(<base_path/desired>) fails when base_path does not exist. #51

Closed
WillBartee opened this issue Apr 10, 2020 · 1 comment

Comments

@WillBartee
Copy link
Contributor

WillBartee commented Apr 10, 2020

As of v2.1.5, the LocalStorage.init will attempt to create a directory for the location provided, however it will fail if there are multiple directories in the path that do not exist.

const fs = require('fs');
const path = require('path');
const assert = require('assert');
const { LocalStorage } = require('node-localstorage');

const non_existent_directory = path.resolve('./does_not_exist');
const non_existent_subdirectory = path.resolve(path.join(non_existent_directory, 'desired_location'));

const storage = new LocalStorage(non_existent_subdirectory);

Throws the error:

 Error: ENOENT: no such file or directory, mkdir 'C:\Workspaces\my-app\does_not_exist\desired_location'
    at Object.mkdirSync (fs.js:753:3)
    at LocalStorage._init (C:\Workspaces\my-app\node_modules\node-localstorage\LocalStorage.js:183:14)
    at new LocalStorage (C:\Workspaces\my-app\node_modules\node-localstorage\LocalStorage.js:124:12)
    at Object.<anonymous> (C:\Workspaces\my-app\main.js:16:19)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)

As of Node.js v10.12:

  • fs
    Added a recursive option to fs.mkdir and fs.mkdirSync. If this option is set to true, non-existing parent folders will be automatically created. #21875
@WillBartee WillBartee changed the title new LocalStorage(<path>) fails when base path does not exist. new LocalStorage(<base_path/desired>) fails when base_path does not exist. Apr 10, 2020
@lmaccherone
Copy link
Owner

This is still open because I haven't pushed an update to npm. I'm trying to catch up now and should be able to do that within a few days.

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

2 participants