Skip to content

Avoid the use of __dirname when importing files dynamically #216

@paulogdm

Description

@paulogdm

Greetings!

Not sure if this issue would fit better on now-builders, but here we go.
Is there a way to avoid the necessity of __dirname when trying to import files locally?
This is our current usage:

 .
├── now.json
├── package.json
└── src
    ├── index.js
    └── temp.txt

index.js:

const {send} = require('micro')
const fs = require('fs')
const {promisify} = require('util')
const readFile = promisify(fs.readFile)
module.exports = async (req, res) => {
  const read = await readFile( __dirname + "/temp.txt")
  return send(res, 200, read.toString())
}

Many users face problems when doing readFile( "./temp.txt"), and the solution is above. But is there a way to avoid it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions