-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
81 lines (71 loc) · 2.74 KB
/
index.js
File metadata and controls
81 lines (71 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//Подключение библиотеки для работы с файловой системой
var fs = require('fs');
//Подключаем библиотеку для HTTP-сервера
var http = require('http');
/*Удаление файлов & папки
fs.unlink('./new-one/some_new.txt', function () {
fs.rmdir('new-one', function () { console.log("Srabotalo!"); });
});
*/
//Создание папки & файлов
// fs.mkdir('new-one', function() {
// fs.writeFile('./new-one/some_new.txt', 'Hello world!', function() {
// console.log("Всё сработало!");
// })
// })
// Чтение и запись файлов потоками
//
// var myReadShort = fs.createReadStream(__dirname + '/big.txt');
// var myWriteShort = fs.createWriteStream(__dirname + '/news.txt');
//
// myReadShort.on('data', function(chunk) {
// console.log("Hoвые данные получены:");
// myWriteShort.write(chunk);
// });
// ****************ЗАПУСКАЕМ СЕРВЕР С МАРШРУТИЗАЦИЕЙ*******************
//
// var server = http.createServer(function(req, res) {
// console.log("URL страницы:" + req.url);
// if ((req.url === '/index') || (req.url === '/') || (req.url === '/style.css')) {
// res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
// fs.createReadStream(__dirname + '/index.html').pipe(res);
// } else if (req.url === '/about') {
// res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
// fs.createReadStream(__dirname + '/about.html').pipe(res);
// } else {
// res.writeHead(404, {'Content-Type': 'text/html; charset=utf-8'});
// fs.createReadStream(__dirname + '/404.html').pipe(res);
// }
// })
//
// server.listen(3000, '127.0.0.1');
// console.log("Мы отслеживаем порт 3000");
// **************РАБОТА С JSON, а также вывод HTML *******************
//
// var server = http.createServer(function(req, res) {
// console.log("URL страницы:" + req.url);
// /*Вывод HTML
// res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
// var myReadShort = fs.createReadStream(__dirname + '/index.html', 'utf8');
// myReadShort.pipe(res);
// */
// //Вывод JSON
// res.writeHead(200, {'Content-Type': 'application/json; charset=utf-8'});
// var obj = {
// model: 'Audi',
// speed: '234',
// wheels: 4
// };
// res.end(JSON.stringify(obj));
// })
//
//
// server.listen(3000, '127.0.0.1');
// console.log("Мы отслеживаем порт 3000");
//Заходить на 127.0.0.1:3000
// // Читаем файл
// fs.readFile('text.txt', 'utf8', function(err, data){
// console.log(data);
// });
// // Создаём
// fs.writeFile('some.txt', 'hi, its me', function(err, data){});