This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const todos = require('./data/todos.json'); | |
const server = http.createServer(function (req, res) { | |
if (res.statusCode > 200) { | |
throw new Error('SERVER NOT STARTED', res.statusCode); | |
} | |
if (req.url == '/todos') { | |
res.writeHead(200, {'Content-Type': 'application/json'}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Title</title> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const github = require('./github'); | |
const username = process.argv[2]; | |
github.getRepos(username, function (err, repos) { | |
if (err) { | |
throw new Error(`ERROR HAS OCCURED... ${err.message}`); | |
} else { | |
repos.forEach(function (repo) { | |
console.log(repo.name); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); // подключаем модуль файловой системы | |
const output = fs.createWriteStream('script.min.js'); // в константу записывает исходящий поток, которая создаёт файл | |
fs.readFile('script.js', 'utf-8', function (err, data) { // читаем файл | |
if (err) { | |
throw new Error('ERROR TO READ FILE...'); // если ошибка, выбрасываем исключение | |
} else { | |
for (let i = 0; i < data.length; i++) { // пробегаемся по всем символам | |
if (data[i] != ' ' && data[i] != '' && data[i] != '\n' && data[i] != '\t') { // если не '', ' ', \n, \t | |
output.write(data[i]); // записываем каждый символ в файл |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); // подключаем файловую систему | |
const input = fs.createReadStream('lorem.txt'); // создаём поток чтения | |
const output = fs.createWriteStream('newlorem.txt'); // создаём поток записи | |
input.pipe(output); // из чтения передаём данные в запись и создаём новый файл |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const streamInput = fs.createReadStream('ent.mp4'); // входящий поток | |
const streamOutput = fs.createWriteStream('new.mp4'); // исходящий поток | |
streamInput.on('data', function (part) { // событие на входящем потоке | |
streamOutput.write(part); // записывает части данных в файл new.mp4 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const stream = fs.createReadStream('natural.txt', 'utf-8'); // создаём поток чтения | |
let records = ''; | |
stream.on('data', function (part) { // вешаем событие с данными и по частям дописываем в переменную, данные которые пришли | |
console.log(records += part); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Н Ё Х | |
const EventEmiter = require('events'); | |
class Timer extends EventEmiter { | |
constructor(total) { | |
super(); | |
this.total = total; | |
this.ticks = 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const EventEmiter = require('events'); // подключаем модуль | |
const myEE = new EventEmiter(); | |
myEE.on('ready', function () { // создаём событие ready | |
console.log('is ready ...'); | |
}); | |
myEE.on('start', function () { // создаём событие start | |
console.log('is start ...'); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Файловая система | |
/* | |
+++Задание 1 | |
Реализовать программу, которая синхронно читает файл и выводит количество строк(\n) содержащихся в файле в консоль | |
*/ | |
/* | |
const fs = require('fs'); | |
var file = fs.readFileSync('test.txt', 'utf-8'); | |
file = file.split('\n'); |