Starting with N|Solid 2.4.0, it's possible to profile your application from the
very beginning, including startup and initialization.

If your N|Solid runtime becomes successfully connected to the N|Solid Console
before the profile ends, the profile data will be saved and can be viewed or
downloaded in your Console.

If you do become connected and the application ends prior to the profile
duration (maximum of 10 minutes) concludes, the profile will be completed and
sent to the Console, assuming it remains connected during exit. If the process
exits abnormally via default signal handler or process crash, the profile
cannot be saved. Exits due to unhandled exception and user signal handlers
will be captured if possible.

One simple way to enable this is to write a small module that begins the
profile, and then load this module via the -r flag.

Contents of profile-app.js

// Profile from application startup.  If you do not specify a duration (milliseconds),
// N|Solid will profile for the maximum duration of 10 minutes.
const duration = 10 * 60 * 1000
require('nsolid').profile(duration)

// If you intend to interrupt your process with a ^C, set a handler so the
// profile can be captured
process.on('SIGINT', () => { process.exit(0) })

Utilize it while running your application

nsolid -r ./profile-app.js your-application.js

As an alternative, you may place this method call directly in your application
or a module loaded by it, but realize that code and modules executed prior to
this cannot be included in the profile.

'use strict'

// Do this first if possible
require('./profile-app')

// Now load other modules and begin your application
const express = require('express')

function MyApplicationCode () {
}