Node.js - performance.now is not a function
Asked Answered
G

1

11

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?

Grieg answered 1/6, 2018 at 15:1 Comment(2)
try const {performance} = require('perf_hooks');Disulfiram
nodejs.org/dist/latest-v10.x/docs/api/…Piecrust
D
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;
Disulfiram answered 1/6, 2018 at 15:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.