How to install npm dependencies for plugins?

Hi guys,

Go question on installing npm dependencies for my plugins. How do you do it? I know HollaEx plugins include some pre-installed dependencies, but what is best way to use them?

Also, how to add other libraries beyond the above?

2 Likes

You don’t install npm packages manually inside a HollaEx plugin.

Instead, plugins support a prescript field in the plugin’s .json file. This is the recommended and supported way to install dependencies.

You can define multiple npm packages there, and they’ll be installed automatically when the plugin is built/loaded.

Example:

"prescript": {
  "run": null,
  "install": [
    "aws-sdk",
    "awesome-phonenumber"
  ]
}

If you need a specific version, you can specify it directly:

"install": [
  "[email protected]",
  "[email protected]"
]

Notes / best practices

  • HollaEx plugins already have access to some pre-installed core dependencies, so you don’t need to reinstall common libraries unless you need a specific version.
  • Any additional third-party library can be added via prescript.
  • Avoid very large or unnecessary dependencies to keep plugin load time fast.
  • Version pinning is recommended for production plugins to avoid unexpected breaking changes.

Below is a list of libraries that are already available in the plugins:

[
  "express",
  "morgan",
  "cors",
  "latest-version",
  "npm-programmatic",
  "sequelize",
  "eval",
  "hollaex-tools-lib",
  "lodash",
  "express-validator",
  "multer",
  "moment",
  "mathjs",
  "bluebird",
  "umzug",
  "request-promise",
  "uuid",
  "jsonwebtoken",
  "moment-timezone",
  "json2csv",
  "flat",
  "ws",
  "node-cron",
  "random-string",
  "bcryptjs",
  "expect-ct",
  "validator",
  "otp",
  "geoip-lite",
  "nodemailer",
  "ws-heartbeat",
  "winston",
  "elastic-apm-node",
  "winston-elasticsearch-apm",
  "triple-beam",
  "uglify-js",
  "body-parser",
  "express-limiter"
]
2 Likes