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
- Open the command palette
(Ctrl+Shift+P
orCmd+Shift+P on Mac)
. - Type
MERN: Node.js Function
and pressEnter
. - Select the function to create (
Read File
,Write File
) and enter the file name. - Press
Enter
and the snippet will be created.
Show GIF
"Big results require big ambitions." - Heraclitus