Intro to NodeJS with learnyounode

This post is being added retrospectively in order to consolidate all of my learning info in one searchable place. Comments are new (May 2022) but the code is old…use at your own risk!

In June 2017 I attended a NodeSchool workshop which was intended to be an introduction to NodeJS. I arrived knowing nothing and left feeling like I knew even less 😂 Anyway here’s the code from the learnyounode workshopper

Exercise 1

console.log("HELLO WORLD");

Exercise 2

// console.log(process.argv);
var sum = 0;

for (var i = 2; i < process.argv.length; i++) {
sum += Number(process.argv[i]);
}

console.log(sum);

Exercise 3

var fs = require('fs');
var contents = fs.readFileSync(process.argv[2]);
var split = contents.toString().split('\n');

var sum = split.length - 1;;

console.log(sum);

Exercise 4

var fs = require('fs');
var contents = fs.readFile(process.argv[2]);
var split = contents.toString().split('\n').length - 1;

console.log(split);