Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can i do require() and dynamic require #108

Open
ezioruan opened this issue Jan 30, 2018 · 1 comment
Open

how can i do require() and dynamic require #108

ezioruan opened this issue Jan 30, 2018 · 1 comment

Comments

@ezioruan
Copy link

i have the following code

const routersDir = path.resolve(path.join(__dirname, 'routers'))

const getRouters = () =>
  fs.readdirSync(routersDir).forEach(file => {
    if (path.extname(file) === '.js') {
      const filePath = path.join(routersDir, file);
      console.log("filePath", filePath)
      const router = require(filePath)
      console.log("router", router)
    }
  })

i want to load the module in a dir
but i got error

 const router = require(filePath)
                     ^
Error: Cannot find module "."
@dsseng
Copy link

dsseng commented Feb 11, 2018

does this code work in the default node.js?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants