-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Closed
Labels
OutputRelated to the the output configuration option.Related to the the output configuration option.
Milestone
Description
Feature request
Is your feature request related to a problem? Please describe.
It's currently not possible to read files from API routes or pages.
Describe the solution you'd like
I want to be able to call fs.readFile with a __dirname path and have it "just work".
This should work in Development and Production mode.
Describe alternatives you've considered
This may need to integrate with @zeit/webpack-asset-relocator-loader in some capacity. This plugin handles these types of requires.
However, it's not a necessity. I'd be OK with something that only works with __dirname and __filename (no relative or cwd-based paths).
Additional context
Example:
// pages/api/test.js
import fs from 'fs'
import path from 'path'
export default (req, res) => {
const fileContent = fs.readFileSync(
path.join(__dirname, '..', '..', 'package.json'),
'utf8'
)
// ...
}Note: I know you can cheat the above example ☝️ with
require, but that's not the point. 😄
amytych, juice49, ScottSmith95, vinpac, JoseCage and 178 moretimneutkens, JoseCage, karpawich, BjoernRave, offero and 35 morelalit2005, Johnrobmiller, SandroMaglione and JulianPhillips
Metadata
Metadata
Assignees
Labels
OutputRelated to the the output configuration option.Related to the the output configuration option.