javascriptnode.jsexpresspackage.json

How to have configure _moduleAliases in Express js (Node JS)


I need to proper coding related to node path.

For example:-

var file = "../module/filePath.js";

var file2 = "../module/filePath2.js"

Need to have

var file = "@module/filePath"

var file2 = "@module/filePath2"


Solution

  • You can use module-alias. It lets you define a custom module path:

    "_moduleAliases": {
      "@root"      : ".", // Application's root
      "@deep"      : "src/some/very/deep/directory/or/file",
      "@my_module" : "lib/some-file.js",
      "something"  : "src/foo", // Or without @. Actually, it could be any string
    }