I want to use fs module inside api route file to do some filesystem operations, however, I get this error: Module not found: Can't resolve 'fs'
. Not only, I can't use the fs inside my handler function, but also I can't start the project since fs error prevents that.
This is what my file looks like.
Path: pages/api/getSchema.js
Content:
const fs = require("fs");
export default function handler(req, res) {
const id = req.query.id;
if(id){
const schemas = require('../../pageSchemas/index.json');
res.end(JSON.stringify(schemas[id]));
}
}