Skip to content

Import json file with different name #1850

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

Closed
johnroper100 opened this issue Apr 8, 2019 · 1 comment
Closed

Import json file with different name #1850

johnroper100 opened this issue Apr 8, 2019 · 1 comment

Comments

@johnroper100
Copy link

  • Node.js Version: 11
  • OS: Ubuntu 18.04
  • Scope (install, code, runtime, meta, other?): Code

I have been able to import json files using require("myfile.json");. I have some files that are actually json but are named with a different file extension (myfile.jlib for example). How can I require them as normal json without changing the filename?

@richardlau
Copy link
Member

The deprecated way is to use require.extensions.

I'm not aware of a replacement for the CommonJS module loader (require()) other than to read the file in with something like fs.readFile() and calling JSON.parse() on the results.

For ECMAScript modules (esm) the replacement seems to be to use loader hooks.

cc @nodejs/modules

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