[Solved] Node.js throws a “ENOENT” when I trying to write a file with a name too large

SleepWritten Asks: Node.js throws a “ENOENT” when I trying to write a file with a name too large
I’m writing a session library for Express.js that stores the sessions in encrypted files. The basic interfaces hierarchy is:

Code:
export interface Current<T = any> {
    load(): Promise<T>;
    save(value: T): Promise<void>;
}

export interface Manager {
    current<T = any>(): Current<T>;
    create(): Promise<void>;
    delete(): Promise<void>;
    rewind(): void;
}

declare global {
  namespace Express {
    export interface Request {
      session: Manager;
    }
  }
}

Every session is stored in a JSON file, which name is a unique hash id. That hash is returned to the client as a cookie. The implementation it’s like that:

Code:
import { sessionCrossover } from '.';
import express from 'express';

const app = express();
app.use(sessionCrossover({
    path: './data',
    expires: 1000 * 10,
    hashLength: 126
}));

You can set the current hash length in the middleware shown before. The problem is this:

  • When you set a hash of a 126 bytes or more, node.js throws an “ENOENT” error (path not found).
  • When the hash is 125 bytes or less the file with the session it’s created normally.

My questions are:

  • Why node.js thows an “ENOENT” (path not found error) when i try to create a file with a large filename?
  • Exists a method to detect a “too large filesize” exception in windows?

Ten-tools.com may not be responsible for the answers or solutions given to any question asked by the users. All Answers or responses are user generated answers and we do not have proof of its validity or correctness. Please vote for the answer that helped you in order to help others find out which is the most helpful answer. Questions labeled as solved may be solved or may not be solved depending on the type of question and the date posted for some posts may be scheduled to be deleted periodically. Do not hesitate to share your response here to help other visitors like you. Thank you, Ten-tools.