Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lesson 2 #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/blog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello, ninjas
1 change: 1 addition & 0 deletions docs/blog2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello, again
360 changes: 360 additions & 0 deletions docs/blog3.txt

Large diffs are not rendered by default.

Empty file added docs/blog4.txt
Empty file.
47 changes: 47 additions & 0 deletions files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const fs = require('fs');

// reading files
fs.readFile('./docs/blog.txt', (err, data) => {
if (err) {
console.log(err);
}
console.log(data.toString());
});

// console.log('last line');

// writing files
fs.writeFile('./docs/blog.txt', 'hello, world', () => {
console.log('file was written');
});

fs.writeFile('./docs/blog2.txt', 'hello, again', () => {
console.log('file was written');
});

// directories
if (!fs.existsSync('./assets')) {
fs.mkdir('./assets', err => {
if (err) {
console.log(err);
}
console.log('folder created');
});
} else {
fs.rmdir('./assets', err => {
if (err) {
console.log(err);
}
console.log('folder deleted');
});
}

// deleting files
if (fs.existsSync('./docs/deleteme.txt')) {
fs.unlink('./docs/deleteme.txt', err => {
if (err) {
console.log(err);
}
console.log('file deleted');
});
}
28 changes: 28 additions & 0 deletions global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const speak = () => {
console.log('hello, ninjas');
}

speak();

// Global Object

// console.log(global);

// global.setTimeout(() => {
// console.log('in the timeout');
// }, 3000);

setTimeout(() => {
console.log('in the timeout');
clearInterval(int);
}, 3000);

const int = setInterval(() => {
console.log('in the interval');
}, 1000);

console.log(__dirname);
console.log(__filename);

// no access to DOM methods
console.log(document.querySelector);
19 changes: 19 additions & 0 deletions modules.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// const people = require('./people');

// console.log(people);

// const data = require('./people');

// console.log(data.people, data.ages);

const { people, ages } = require('./people');

console.log(people, ages);

const os = require('os');

console.log(os.platform(), os.homedir());




11 changes: 11 additions & 0 deletions people.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const people = ['yoshi', 'ryu', 'chun-li', 'mario'];
const ages = [20, 25, 30, 35];

// console.log(people);

// module.exports = people;

module.exports = {
people,
ages,
}
14 changes: 14 additions & 0 deletions streams.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');

const readStream = fs.createReadStream('./docs/blog3.txt', { encoding: 'utf8'});
const writeStream = fs.createWriteStream('./docs/blog4.txt');

readStream.on('data', chunk => {
// console.log('---- NEW CHUNK ----');
// console.log(chunk);
writeStream.write('\nNEW CHUNK:\n');
writeStream.write(chunk);
});

// piping
// readStream.pipe(writeStream);