最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node.js - performance.now is not a function - Stack Overflow

programmeradmin3浏览0评论

I have a Node.js app. When I run node -v from the command-line, I see the following:

v10.3.0

This is relevant because I'm interested in using the Performance Hooks. I've created the most basic thing I can think of, which looks like this in an in a file named 'index.js':

const performance = require('perf_hooks');

let p = performance.now();

When I run node index.js from the command-line, I get an error that says:

TypeError: performance.now is not a function

Why am I getting this error? What am I missing?

I have a Node.js app. When I run node -v from the command-line, I see the following:

v10.3.0

This is relevant because I'm interested in using the Performance Hooks. I've created the most basic thing I can think of, which looks like this in an in a file named 'index.js':

const performance = require('perf_hooks');

let p = performance.now();

When I run node index.js from the command-line, I get an error that says:

TypeError: performance.now is not a function

Why am I getting this error? What am I missing?

Share Improve this question edited Mar 2, 2023 at 12:36 sideshowbarker 88.1k29 gold badges214 silver badges211 bronze badges asked Jun 1, 2018 at 15:01 Some UserSome User 5,82716 gold badges55 silver badges95 bronze badges 2
  • 2 try const {performance} = require('perf_hooks'); – J. Pichardo Commented Jun 1, 2018 at 15:02
  • nodejs.org/dist/latest-v10.x/docs/api/… – axiac Commented Jun 1, 2018 at 15:13
Add a comment  | 

1 Answer 1

Reset to default 27

The perf_hooks module exports several things, one of them is performance, so using object destructuring you could do:

const { performance } = require('perf_hooks');

Or with object access:

const performance = require('perf_hooks').performance;
发布评论

评论列表(0)

  1. 暂无评论