diff --git a/package-lock.json b/package-lock.json index 9de40f7..73cc18c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@types/express": "^4.17.13", "@types/express-serve-static-core": "^4.17.28", "@types/koa": "^2.13.4", + "app-root-path": "^3.1.0", "debug": "^3.2.6", "lodash.get": "^4.4.2", "pkginfo": "^0.4.1" @@ -1051,6 +1052,14 @@ "node": ">= 8" } }, + "node_modules/app-root-path": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.1.0.tgz", + "integrity": "sha512-biN3PwB2gUtjaYy/isrU3aNWI5w+fAfvHkSvCKeQGxhmYpwKFUxudR3Yya+KqVRHBmEDYh+/lTozYCFbmzX4nA==", + "engines": { + "node": ">= 6.0.0" + } + }, "node_modules/append-field": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", @@ -9326,6 +9335,11 @@ "picomatch": "^2.0.4" } }, + "app-root-path": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/app-root-path/-/app-root-path-3.1.0.tgz", + "integrity": "sha512-biN3PwB2gUtjaYy/isrU3aNWI5w+fAfvHkSvCKeQGxhmYpwKFUxudR3Yya+KqVRHBmEDYh+/lTozYCFbmzX4nA==" + }, "append-field": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/append-field/-/append-field-1.0.0.tgz", diff --git a/package.json b/package.json index 40bd799..1ef2721 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "@types/express": "^4.17.13", "@types/express-serve-static-core": "^4.17.28", "@types/koa": "^2.13.4", + "app-root-path": "^3.1.0", "debug": "^3.2.6", "lodash.get": "^4.4.2", "pkginfo": "^0.4.1" diff --git a/src/index.js b/src/index.js index 8f9958f..4fbb3c2 100644 --- a/src/index.js +++ b/src/index.js @@ -1,8 +1,7 @@ 'use strict'; - -const Path = require('path'); +var appRoot = require('app-root-path'); const metricsMiddleware = { exports: {} }; -require('pkginfo')(metricsMiddleware, { dir: Path.dirname(module.parent.filename), include: ['name', 'version'] }); +require('pkginfo')(metricsMiddleware, { dir: appRoot.path, include: ['name', 'version'] }); const appVersion = metricsMiddleware.exports.version; const projectName = metricsMiddleware.exports.name.replace(/-/g, '_');