Cannot find module 'elastic-apm-node'

Hi there

I'm new to Elastic APM and I'm using ELK and App server 7.7. I've managed to get APM to talk to ELK.

I've been tasked to monitor Node.JS and I thought I'll start by simply monitoring a simple 'Hello World' code.

I'm using a simple code in app.js like so:

const http = require('http');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

How do I get a Node JS agent to monitor this?

I have installed agent like so in an offline machine:

sudo npm install elastic-apm-node-3.6.1.tgz --save

I do not know if this is correct since I can't find any doc to show me how to install agent in an offline manner.

I have inserted the following code at the top of app.js:

// Add this to the VERY top of the first file loaded in your app
var apm = require('elastic-apm-node').start({
  // Override service name from package.json
  // Allowed characters: a-z, A-Z, 0-9, -, _, and space
  serviceName: 'testApp',

  // Use if APM Server requires a token
  secretToken: '',

  // Set custom APM Server URL (default: http://localhost:8200)
  serverUrl: 'http://10.10.10.10:8200'
})

Again I do not know if this is correct since I'm not familiar with Node.JS and the doc seems to assume I have a fair grasp of it.

When I run "node app.js", I get the following error:

Error: Cannot find module 'elastic-apm-node'
    at Function.Module._resolveFilename (module.js:476:15)
    at Function.Module._load (module.js:424:25)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/user/app.js:1:101)
    at Module._compile (module.js:577:32)
    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)

Again I do not know if this is even the correct way to insert code but I can't get any more clue out of the documentation.

Can anyone pls assist me? Any step by step instruction will be really helpful. Thanks.

ck

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