-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
170 lines (135 loc) · 4.58 KB
/
index.js
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// var http = require('http');
// http.createServer(function (req, res) {
// res.writeHead(200, {'Content-Type': 'text/html'});
// //Return the url part of the request object:
// res.write(req.url);
// res.end();
// }).listen(8080);
// var http = require('http');
// var url = require('url');
// http.createServer(function (req, res) {
// res.writeHead(200, {'Content-Type': 'text/html'});
// var q = url.parse(req.url, true).query;
// var txt = q.year + " " + q.month;
// res.end(txt);
// }).listen(8080);
// var http = require('http');
// var fs = require('fs');
// http.createServer(function (req, res) {
// fs.readFile('./hello_world.txt', function(err, data) {
// res.writeHead(200, {'Content-Type': 'text/html'});
// res.write(data);
// return res.end();
// });
// }).listen(8080);
// var fs = require('fs');
// fs.appendFile('mynewfile1.txt', 'Hello content!', function (err) {
// if (err) throw err;
// console.log('Saved!');
// });
// var fs = require('fs');
// fs.open('mynewfile1.txt', 'w', function (err, file) {
// if (err) throw err;
// console.log('Saved!');
// });
// var fs = require('fs');
// fs.writeFile('mynewfile3.txt', 'Hello content!', function (err) {
// if (err) throw err;
// console.log('Saved!');
// });
// var fs = require('fs');
// fs.appendFile('mynewfile1.txt', ' This is my text.', function (err) {
// if (err) throw err;
// console.log('Updated!');
// });
// var fs = require('fs');
// fs.writeFile('mynewfile3.txt', 'This is my text', function (err) {
// if (err) throw err;
// console.log('Replaced!');
// });
// var fs = require('fs');
// fs.unlink('mynewfile2.txt', function (err) {
// if (err) throw err;
// console.log('File deleted!');
// });
// var fs = require('fs');
// fs.rename('mynewfile1.txt', 'myrenamedfile.txt', function (err) {
// if (err) throw err;
// console.log('File Renamed!');
// });
// var url = require('url');
// var adr = 'http://localhost:8080/default.htm?year=2017&month=february';
// var q = url.parse(adr, true);
// console.log(q.host); //returns 'localhost:8080'
// console.log(q.pathname); //returns '/default.htm'
// console.log(q.search); //returns '?year=2017&month=february'
// var qdata = q.query; //returns an object: { year: 2017, month: 'february' }
// console.log(qdata.month); //returns 'february'
// var http = require('http');
// var url = require('url');
// var fs = require('fs');
// http.createServer(function (req, res) {
// var q = url.parse(req.url, true);
// var filename = "." + q.pathname;
// fs.readFile(filename, function(err, data) {
// if (err) {
// res.writeHead(404, {'Content-Type': 'text/html'});
// return res.end("404 Not Found");
// }
// res.writeHead(200, {'Content-Type': 'text/html'});
// res.write(data);
// return res.end();
// });
// }).listen(8080);
// var http = require('http');
// var uc = require('upper-case');
// http.createServer(function (req, res) {
// res.writeHead(200, {'Content-Type': 'text/html'});
// res.write(uc.upperCase("Hello World!"));
// res.end();
// }).listen(8080); //not working
// var http = require('http');
// var formidable = require('formidable');
// var fs = require('fs');
// http.createServer(function (req, res) {
// if (req.url == '/fileupload') {
// var form = new formidable.IncomingForm();
// form.parse(req, function (err, fields, files) {
// var oldpath = files.filetoupload.filepath;
// var newpath = 'C:/Users/Your Name/' + files.filetoupload.originalFilename;
// fs.rename(oldpath, newpath, function (err) {
// if (err) throw err;
// res.write('File uploaded and moved!');
// res.end();
// });
// });
// } else {
// res.writeHead(200, {'Content-Type': 'text/html'});
// res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
// res.write('<input type="file" name="filetoupload"><br>');
// res.write('<input type="submit">');
// res.write('</form>');
// return res.end();
// }
// }).listen(8080);
// var nodemailer = require('nodemailer');
// var transporter = nodemailer.createTransport({
// service: 'gmail',
// auth: {
// user: '[email protected]',
// pass: 'yourpassword'
// }
// });
// var mailOptions = {
// from: '[email protected]',
// to: '[email protected]',
// subject: 'Sending Email using Node.js',
// text: 'That was easy!'
// };
// transporter.sendMail(mailOptions, function(error, info){
// if (error) {
// console.log(error);
// } else {
// console.log('Email sent: ' + info.response);
// }
// });