NodeJS: Store and access logs

For informations about making log persistent for other languages please visit this page

NodeJS automatically limits the length of the logs output FlashDrive stores when execution fails. While it’s not possible to access detailed logs on the builder because builds happens on an ephemeral instance destroyed when the build finishes, you can access detailed logs during your app running phase by using a Virtual Disk :

Determine where NodeJS loggued the event :

Check the “Logs” page of your app and isolate the line with the detailed log directory :

For this event, NPM wrote the error on /app/.npm/_logs, to be able to access the log file and keep it between app reboot we need to make this directory persistent by linking it to a Virtual Disk managed by FlashDrive. Each app includes 10GB of Virtual Disk Space no matter the size of the app or it’s location.

To make logs persistent :

  • Create a virtual disk inside your app with the path to /app/ (or /app/.npm/ if you want to store only the NPM logs)

Logs are now kept inside the virtual disk instead of the container temporary disk and are included in backups and are never erased.

You can now export your logs using a Filebrowser app installed inside the same stack as your app (available here from the Marketplace).

After installing FileBrowser inside the same stack as your NodeJS app, make sure to visit the app page settings and link it to the Virtual Disk you created for your app.

Logs export and analysis can also be built directly inside your app or via a plugin.

Important: make sure to review and delete your virtual disk usage regularly, the virtual disk space included with each app is limited and overage is billed $0.016/GB/day ($0.50/GB/month) which can quickly become very expensive.

FlashDrive file architecture automatically detects and treats the virtual disks as part of the container file system, this means you can create a virtual disk with the path /app/.npm/, and all others logs will stays inside the container temporary disk (and not made persistent). This can help save disk space and time.

You can delete the /app/ virtual disk at any time, the app will automatically revert to the container temporary disk.

Was this helpful?

4 / 1