Read File Preview CLI
NodeJS
Medium
3 views
Problem Description
Read a file path from args and print first 100 chars.
Output Format
Print preview or FAIL.
Constraints
Use fs.readFileSync with try/catch.
Official Solution
const fs = require('fs');
const p = process.argv[2];
if (!p) {
console.log('FAIL');
process.exit(0);
}
try {
const txt = fs.readFileSync(p, 'utf8');
console.log(txt.slice(0, 100));
} catch (e) {
console.log('FAIL');
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!