Skip to content

node: util.promisify(fs.exists) always rejects #2408

@kt3k

Description

@kt3k

util.promisify works differently in node and deno_std/node when the fs.exists is passed to it.

The following code prints Error!!!\ntrue (assuming README.md exists in current dir)

import { promisify } from "https://deno.land/[email protected]/node/util.ts";
import { exists } from "https://deno.land/[email protected]/node/fs.ts";
const pExists = promisify(exists);
try {
  const result = await pExists("README.md")
  console.log("exists", result);
} catch(e) {
  console.log("Error!!!");
  console.log(e)
}

On the othe hand, the following prints Success\ntrue with node.js:

const util = require("util");
const fs = require("fs");
const pExists = util.promisify(fs.exists);
pExists("README.md").then(x => {
  console.log("Success");
  console.log(x)
}).catch((e) => {
  console.log("Error!!!");
  console.log(e)
})

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions