I am running a server in which users get a javascript file when they sign up. They can use this on their website, and I can track it.
So people register through my expressjs project, but to change the JS file they will receive, i use this code.
if (checkExists[0]['COUNT(1)'] == 1n) {
const options = {
files: 'src/sdk.js',
from: 'var Hh="-4534939823",',
to: `var Hh="${chatId}",`,
}
fs.copyFile('theFile.js', 'src/sdk.js', (err) => { //copy file to
if (err) throw err;
});
try { //replace chatID
const result = await replaceInFile(options)
console.log(result)
}
catch (error) {
console.error(error)
}
child_process.execSync(`zip -r src.zip src`);
a.finally(() => {
child_process.exec('rm src/sdk.js; rm src.zip')
})
}
So i create a duplicate of the original -> edit lines -> zip the file -> send it back
I have a big feeling that this will fail over time. Is there a standard way / package in Node for such tasks?
it works, but is it optimal?
3