# Elastic node apm not adding hooks for express

**URL:** <https://discuss.elastic.co/t/elastic-node-apm-not-adding-hooks-for-express/192833>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [July 30, 2019, 6:36am UTC](https://discuss.elastic.co/t/elastic-node-apm-not-adding-hooks-for-express/192833 "2019-07-30T06:36:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pksinghal](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@pksinghal](https://discuss.elastic.co/u/pksinghal)\
**Post date:** [July 30, 2019, 6:36am UTC](https://discuss.elastic.co/t/elastic-node-apm-not-adding-hooks-for-express/192833/1 "2019-07-30T06:36:47Z")

</div>

Hi,  
I am using express 4.16.2 version.  
To use node APM , we added following line at the start of code in index.js server file.  
Code : import apm from 'elastic-apm-node/start';  
When we run, node APM not sending any data to apm -server.  
So we created custom error to check if APM is working and we get these error, but didn't get transaction data.  
We change logLevel to debug for APM and found that APM not adding hook for express.  
Logs as follows :

> pwa@0.1.0 build:start /home/PWA  
> node dist/server.bundle.dev.js

adding hook to Node.js module loader  
shimming https@8.10.0 module  
shimming https.Server.prototype.emit function  
listening on 3000...

---

<div class="post-metadata">

**Author:** ![stephenbelanger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenbelanger/32/34880_2.png) [@stephenbelanger](https://discuss.elastic.co/u/stephenbelanger)\
**Post date:** [July 30, 2019, 7:12am UTC](https://discuss.elastic.co/t/elastic-node-apm-not-adding-hooks-for-express/192833/2 "2019-07-30T07:12:20Z")

</div>

What Node.js version are you using? Are you using babel to support that import statement, or are you using the new es modules support built into Node.js?

---

<div class="post-metadata">

**Author:** ![pksinghal](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@pksinghal](https://discuss.elastic.co/u/pksinghal)\
**Post date:** [July 30, 2019, 7:19am UTC](https://discuss.elastic.co/t/elastic-node-apm-not-adding-hooks-for-express/192833/3 "2019-07-30T07:19:25Z")

</div>

Node version : v8.10.0  
Yes , we are using new es modules support built into Node.js.  
import apm from 'elastic-apm-node/start';

---

<div class="post-metadata">

**Author:** ![stephenbelanger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenbelanger/32/34880_2.png) [@stephenbelanger](https://discuss.elastic.co/u/stephenbelanger)\
**Post date:** [July 30, 2019, 7:45am UTC](https://discuss.elastic.co/t/elastic-node-apm-not-adding-hooks-for-express/192833/4 "2019-07-30T07:45:39Z")

</div>

The es module support in Node.js is still experimental in 12.x. As such, the implementation could break compatibility at any time. I would recommend using babel to transpile it to require, for the time being.

---

<div class="post-metadata">

**Author:** ![pksinghal](https://avatars.discourse-cdn.com/v4/letter/p/f19dbf/32.png) [@pksinghal](https://discuss.elastic.co/u/pksinghal)\
**Post date:** [July 30, 2019, 7:51am UTC](https://discuss.elastic.co/t/elastic-node-apm-not-adding-hooks-for-express/192833/5 "2019-07-30T07:51:22Z")

</div>

We are also using with babel-loader for the same through webpack but problem still exists.

webpack server config

var webpack = require('webpack');  
//var path = require('path');  
//const nodeExternals = require('webpack-node-externals');

const getClientEnvironment = require('./env');  
const paths = require('./paths');  
const publicPath = paths.servedPath;  
const publicUrl = publicPath.slice(0, -1);  
const env = getClientEnvironment(publicUrl);  
env.stringified = {...env.stringified,'isClientEnv':JSON.stringify(false)};  
var LodashModuleReplacementPlugin = require('lodash-webpack-plugin');

const config = {  
entry: {  
server: paths.serverIndexJs,  
},  
output: {  
filename: '[name].bundle.dev.js',  
path: paths.serverBuildPath,  
chunkFilename: '[name].[chunkhash].js'  
},  
mode : env.raw.NODE\_ENV,  
target : 'node',  
// externals: [nodeExternals()],  
resolve: {  
modules: ['node\_modules', 'src'],  
extensions: ['\*', '.js', '.json']  
},  
module: {  
rules: [  
// {  
// test: [/.bmp$/, /.gif$/, /.jpe?g$/, /.png$/],  
// loader: require.resolve('url-loader'),  
// options: {  
// limit: 10000,  
// name: 'static/media/[name].[hash:8].[ext]',  
// },  
// },  
{  
test: /.(jsx|js)?$/,  
exclude: /(node\_modules/)/,  
use: {  
loader: "babel-loader"  
}

```
        },
        {
            test: /\.css$/,
            use: [
                {
                    loader: "css-loader/locals"
                }
            ]
        }
    ],

},
plugins: [
    new webpack.DefinePlugin(env.stringified),
    new LodashModuleReplacementPlugin
]

```

};  
module.exports = config;

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 20, 2019, 3:51am UTC](https://discuss.elastic.co/t/elastic-node-apm-not-adding-hooks-for-express/192833/6 "2019-08-20T03:51:24Z")

</div>

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