Defining public Constants file in node.js
You write constants object into TRIP_STATUS object. So, you can get them with the next way:
console.log(Constants.TRIP_STATUS.TRIP_STAUTS_INITIATED);
Or, you can do with the next way:
module.exports = {
TRIP_STAUTS_INITIATED : 1000,
...
}
And get constants as you want:
console.log(Constants.TRIP_STAUTS_INITIATED);
constants
is a native module of Node.js like fs
, http
, so require("constants")
will only output native constants. If you want to import your local constant.js, you should require("./constants")
(ABSOLUTE PATH NOT RELATIVE ONE).