APM NodeJS default code is resulting in error

Hello all.

I installed the newest version of APM Server on a machine and I am trying to test an apm agent on another machine. The code is very simple, and I took it straight from Elastic's example:

var apm = require('elastic-apm-node').start({
serviceName: 'testapp',
serverUrl: 'http://192.168.0.180:8200'
})


const express = require('express')
const app = express()
app.get('/', (req, res) => {
 res.send('HEY!')
})
app.listen(3000, () => console.log('Server running on port 3000'))

I tried to delete some line of the code to test where it crashes, and I think it's on the beggining of the file, i.e: var apm = require('elastic-apm-node').start({

The exact error I get is:

/home/user/test/node_modules/read-pkg-up/index.js:6
module.exports = async options => {
                       ^^^^^^^

SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/user/test/node_modules/elastic-apm-node/lib/config.js:8:17)

Does anybody get any idea?

Looks like you're using an unsupported version of Node.js. Version 3.x of the Elastic APM Node.js Agent supports 8.6.0 and higher. Can you confirm which version of Node.js you're using?

For support of Node.js 6.x, you need to use version 2.x of the Elastic APM Node.js Agent, but it is highly recommended at you upgrade your Node.js version to at least version 10.x at this point to get the latest security patches.

1 Like

Thank you very much! That was the problem!! I Installed a newer version and it works!
Thank you again!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.