Updated write file code with proper indentation (#19212)

* Updated write file code with proper indentation

Updated with proper style match and indentation

* Update index.md
This commit is contained in:
FarhanYaseen
2018-10-15 17:14:31 +05:00
committed by A-J Roos
parent d7a7fdbd31
commit 719d40cae0

View File

@ -27,12 +27,12 @@ Node.js code to read file from your computer and return the content to the conso
```javascript ```javascript
const fs = require('fs'); const fs = require('fs');
fs.readFile('input.txt', 'utf-8', (err, data) => { fs.readFile('input.txt', 'utf-8', (err, data) => {
if(err){ if (err) {
console.log(err); console.log(err);
} }
else{ else {
console.log("Content present in input.txt file : " + data.toString()); console.log("Content present in input.txt file : " + data.toString());
} }
}); });
``` ```
The above code reads a file *input.txt* from your computer and returns the content to the console. The above code reads a file *input.txt* from your computer and returns the content to the console.
@ -55,12 +55,12 @@ Node.js code to write content into file.
```javascript ```javascript
const fs = require('fs'); const fs = require('fs');
fs.writeFile('output.txt', "New content added", (err, data) => { fs.writeFile('output.txt', "New content added", (err, data) => {
if(err){ if (err) {
console.log(err); console.log(err);
} }
else{ else {
console.log("The file is saved"); console.log("The file is saved");
} }
}); });
``` ```
The above code creates a file *output.txt* and add content *New content added* to it. The above code creates a file *output.txt* and add content *New content added* to it.