Skip to content

Instantly share code, notes, and snippets.

@MrSimsek
Created November 27, 2018 09:19
Show Gist options
  • Save MrSimsek/772c035a151518214198acb12143338a to your computer and use it in GitHub Desktop.
Save MrSimsek/772c035a151518214198acb12143338a to your computer and use it in GitHub Desktop.
Changed listMajors function
function outputEmployeeHTML(no, name, title, email) {
// If encoding(second parameter) is not specified, readFile outputs Buffer
fs.readFile('./email-template.html', "utf8", (err, html) => {
if(err) console.log(err);
let employeeHTML = html;
const employeeData = {
'{NAME}': name,
'{TITLE}': title,
'{EMAIL}': email
};
employeeHTML = employeeHTML.replace(/{NAME}|{TITLE}|{EMAIL}/gi, function(matched){
return employeeData[matched];
});
const signaturesDirectory = './signatures';
if (!fs.existsSync(signaturesDirectory)){
fs.mkdirSync(signaturesDirectory);
}
if(no !== undefined) {
fs.writeFile(`${signaturesDirectory}/${no}.html`, employeeHTML, 'utf8', (err) => {
if(err) throw err;
console.log(`File ${no} is saved.`);
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment