transforming a script into a function

hello to all I have this script but I can not insert it into a plugin with a function as a fix?

This is code:
Code:
const path = require ('path');
const base = path.dirname (process.mainModule.filename);
const fs = require ('fs');
const fileText = "Prima riga \ nLa seconda riga";
fs.writeFileSync (base + '/test.txt', fileText);
Moderator note: Closing this as it is a suplicate thread.

Original thread: https://forums.rpgmakerweb.com/threads/transforming-a-script-into-a-function.99798/