Skip to main content

Node.js

How to use the Snippet

Write the snippet in your new file !fsrf:

script.js
import fs from 'fs';
import path from 'path';

const filePath = path.join(__dirname, 'filename');

fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error('Error reading file:', err);
return;
}
console.log('File content:', data);
});

In the snippet above, we created a simple Node.js function that reads the content of a file using the fs module. The function reads the content of the file filename located in the same directory as the script file.


How to use the Command

  1. Open the command palette (Ctrl+Shift+P or Cmd+Shift+P on Mac).
  2. Type MERN: Node.js Function and press Enter.
  3. Select the function to create (Read File, Write File) and enter the file name.
  4. Press Enter and the snippet will be created.
Show GIF

Nodejs Function


"Big results require big ambitions." - Heraclitus