Other tutorials of this series.
Notes for this tutorial:
Task for this tutorial:
- Given a CSV file containing the weather data
- Convert each of the weather data into Celsius or Fahrenheit depending on the original unit
- Write the converted weather data into the output file in the same CSV format.
Concepts about software development:
- Understanding the concepts is much more important than knowing the syntax of programming languages
- In order to solve a big problem, always break it into smaller subproblems
Using modules (ES5 CommonJS syntax)
const fs = require("fs");
//process.argv is an array
Read text file line by line
const fileReadStream = fs.createReadStream("filename.txt");
Write text file
const fileWriteStream = fs.createWriteStream("outputFilename.txt");
Blocking (synchronous) calls VS non-blocking (asynchronous) calls
- Blocking: need to wait for the call to complete before you can proceed to the next line
- Non-blocking: you don’t have to wait for the call to complete. You can still execute the subsequent instructions
const someCondition = 'f';
The shorthand for if-else statement
let outputScale = scale === 'c' ? 'F' : 'C';
The source code of the program in this tutorial on GitHub.