How to profile Node.js performance

Identifying performance bottlenecks in Node.js applications is essential for maintaining responsiveness under load, especially in production environments. With over 12 years of Node.js development experience since 2014 and as the creator of CoreUI, I’ve optimized numerous backend systems serving millions of requests. Node.js includes a built-in CPU profiler that integrates with Chrome DevTools, allowing you to visualize function execution times and identify slow code paths. This approach provides production-grade profiling without external dependencies.

Use the --inspect flag with Chrome DevTools Performance tab to profile CPU usage.

node --inspect app.js

Open Chrome, navigate to chrome://inspect, click “inspect”, then open the “Profiler” tab and click “Start”.

For programmatic profiling, use the built-in inspector module:

const inspector = require('inspector')
const fs = require('fs')

const session = new inspector.Session()
session.connect()

session.post('Profiler.enable', () => {
  session.post('Profiler.start', () => {
    // Your code to profile
    performExpensiveOperation()

    session.post('Profiler.stop', (err, { profile }) => {
      fs.writeFileSync('profile.cpuprofile', JSON.stringify(profile))
      session.disconnect()
    })
  })
})

Load the generated profile.cpuprofile file in Chrome DevTools Performance tab.

Best Practice Note

CPU profiling shows which functions consume the most execution time, helping you identify bottlenecks. For memory profiling, use the “Memory” tab to take heap snapshots and detect memory leaks. The --prof flag generates V8 profiling output that can be processed with node --prof-process. This is exactly how we optimize CoreUI dashboard backends—profiling API endpoints under load, identifying slow database queries, and optimizing hot code paths to reduce response times.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author

Subscribe to our newsletter
Get early information about new products, product updates and blog posts.

Answers by CoreUI Core Team