Installation Methods

Review our alternate installation methods.

Most node applications today are either written in CommonJS (CJS), or compiled to CJS before running them. CommonJS uses require() to load modules. Our recommended installation method when using CommonJS is to require the instrument.js file at the top of your application. However, if your application is run in ESM mode, this will not work. In this case, you can follow the ESM docs.

Note that even if your application is written in ESM (using import), it may still be run in CJS. In this case, you should follow the CommonJS instructions.

If you're using TypeScript, your application is likely compiled to CommonJS before running it. In this case, you should follow the CommonJS instructions.

If you are using require() in your application, you should follow the CommonJS instructions.

If you are using import in your application, your installation method depends on how your application is run. If you compile your application (e.g. into a /dist folder or similar) before running this, you need to check how the compiled code looks like. Is the compiled code using require? Then you should follow the CommonJS instructions. If the compiled code is using import, you should follow the ESM instructions.

If you do not compile your code, you'll need to follow the ESM instructions.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").