fs.readFile(tempPath, 'utf-8', (err, source) => { if (err) throw err; const template = handlebars.compile(source); const exportCode = template(data); callback(exportCode); });
const readFile = filePath => { return new Promise((resolve, reject) => { fs.readFile(filePath, 'utf8', (error, fileContent) => { if (error != null) { reject(error); return; } resolve(fileContent); }); }); }
app.get( '/notes/:socketId', function( req, res ) { fs.readFile( opts.baseDir + 'plugin/notes-server/notes.html', function( err, data ) { res.send( Mustache.to_html( data.toString(), { socketId : req.params.socketId })); }); });
async function disableCron() { if (fs.existsSync('./build/wordpress/wp-config.php')) { await fs.readFile('./build/wordpress/wp-config.php', (err, data) => { if (err) { log(wpFy + ' - ' + warning + ' WP_CRON was not disabled!'); } if (data) { if (data.indexOf('DISABLE_WP_CRON') >= 0) { log('WP_CRON is already disabled!'); } else { return src('./build/wordpress/wp-config.php') .pipe(inject.after("define( 'DB_COLLATE', '' );", "\ndefine( 'DISABLE_WP_CRON', true );")) .pipe(dest('./build/wordpress')); } } }); } }
function initHistory() { fs.readFile(HISTORY_FILE, (err, data) => { if(err) { if(err.code === 'ENOENT') { history = []; fs.writeFile(HISTORY_FILE, "[]", (err) => { if(err) { noAccessToHistory = true; console.error(`Failed to write history file ${err.message}`); } }); } else { console.error(`Failed to read history file ${err.message}`); } } else { try { history = JSON.parse(data.toString()); } catch(e) { // corrupted history history = [] } } }); }
lintContentWrapper(null, fs.readFileSync(file, helpers.utf8Encoding)); } else { fs.readFile(file, helpers.utf8Encoding, lintContentWrapper);
}); const readFileAsync = util.promisify(fs.readFile); const rootPath = process.cwd(); let count = 0;
const repos = JSON.parse(await readFile(path.resolve(__dirname, `../../repositories/${type}.json`)));
fs.readFile(file, helpers.utf8Encoding, (err, content) => { if (err) { return callback(err);
}); }); fs.readFile("README.md", helpers.utf8Encoding, function readFile(err, contents) { test.ifError(err);
tape("doc", (test) => { test.plan(336); fs.readFile("doc/Rules.md", helpers.utf8Encoding, (err, contents) => { test.ifError(err);
.then( function configFileExists() { return fs.promises.readFile(configFile, helpers.utf8Encoding) .then(JSON.parse); }, "resultVersion": 3 }), fs.promises.readFile(file, helpers.utf8Encoding), fs.promises.readFile(fixedFile, helpers.utf8Encoding) ]) .then(function validateApplyFixes(fulfillments) { fs.promises.readFile(resultsFile, helpers.utf8Encoding) .then( function fileContents(contents) { return errorObjects; }) : fs.promises.readFile(file, helpers.utf8Encoding) .then( function fileContents(contents) { return test.ok(true); return fs.promises.readFile(file, helpers.utf8Encoding) .then( function applyFixes(content) {
// Promisify readFile async function readFile(file) { const promise = await new Promise((resolve, reject) => { fs.readFile(file, (err, data) => { if (err) reject(err); else resolve(data.toString()); }); }); return promise; }