fs Module

AppSignal for Node.js 3.x can instrument the fs Module, giving you greater insight into what impact file management has on the performance of your application.

The fs Module in Node.js provides an API for interacting with the file system allowing your application to read and write files. The fs module has many functions that enable your application to interact with files, such as mkdir to create new directories and rename to alter a file's name.

Installation

The fs Module is only automatically instrumented in the AppSignal for Node.js package, from version 3.0.0 to 3.0.6.

This module is not enabled by default in version 3.0.7 onwards. To enable this instrumentation, follow the instructions for adding additional instrumentation using the @opentelemetry/instrumentation-fs package. Please note that it may not work due to an upstream issue with the OpenTelemetry instrumentation package for the fs module.

Follow the setup instructions below to view fs events in your application's event timelines.

Usage

To use fs module functions such as readFileSync in your application, add const fs = require('fs') to the top of your app.js file:

javascript
import fs from "fs"; import express from "express"; // or: const fs = require("fs"); // or: const express = require("express"); const app = express(); app.get("/", (req, res) => { const greetings = fs.readFileSync("greetings.txt"); res.send(greetings); });

Once configured, your application's event timelines will report the performance of fs module functions:

fs Module on Event Timeline

fs Module Functions

The functions listed below are supported both in the sync and async variants (i.e. exists and existsSync) and the promise versions from the fs/promises module.

For sync functions, append Sync to the function name, for example: lchown

lchownSync

FunctionPromiseCallbackSync
access✓✓✓
appendFile✓✓✓
chmod✓✓✓
chown✓✓✓
copyFile✓✓✓
cp✓✓✓
lchown✓✓✓
link✓✓✓
lstat✓✓✓
lutimes✓✓✓
mkdir✓✓✓
mkdtemp✓✓✓
open✓✓✓
opendir✓✓✓
readdir✓✓✓
readFile✓✓✓
readlink✓✓✓
realpath✓✓✓
rename✓✓✓
rm✓✓✓
rmdir✓✓✓
stat✓✓✓
symlink✓✓✓
truncate✓✓✓
unlink✓✓✓
utimes✓✓✓
writeFile✓✓✓
lchmod✓⨯⨯
exists✓✓✓