Skip to content

Import json file with different name #1850

Closed

Description

@johnroper100
  • 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?

Activity

  1. richardlau commented on Apr 8, 2019

    @richardlau
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions