0
Normally when I make a server I have no problem importing route files but I’m working on a project using GraphQL which requires me to include "type": "module",
inside my package.json
file. So when I try having this inside my app.js
file
const indexRouter = require("./routes/index");
It gives me this error.
ReferenceError: require is not defined in ES module scope, you can use import instead
How do I use import for a file like that? Inside that file is a bunch of router.get
functions like this:
router.get("/", function (req, res, next) {
res.render("index", { title: "Library" });
});
router.get("/library/:title", function (req, res, next) {
res.render("library");
});
Would I have to manually export every render? Or is there a simpler solution I can’t seem to figure out?
|