Created
November 27, 2018 09:19
-
-
Save MrSimsek/772c035a151518214198acb12143338a to your computer and use it in GitHub Desktop.
Changed listMajors function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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