-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnode09.js
More file actions
32 lines (28 loc) · 807 Bytes
/
node09.js
File metadata and controls
32 lines (28 loc) · 807 Bytes
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
var net = require('net')
var port = process.argv[2];
function dateFormat(year,mon,date,h,min){
var YYYY = ("0000" + year).slice(-4);
var MM = ("00" + (mon+1)).slice(-2);
var dd = ("00" + date).slice(-2);
var hh = ("00" + h).slice(-2);
var mm = ("00" + min).slice(-2);
return `${YYYY}-${MM}-${dd} ${hh}:${mm}` //テンプレート文字列
}
function currentDate(){
var date = new Date();
var dateArray = [date.getFullYear(),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes()];
return dateFormat.apply(null, dateArray);
}
var server = net.createServer(function (socket) {
socket.write(currentDate() + "\n");//\nは終了の印(TCPのルール)
socket.end();
})
server.listen(port)
/*
-h
--help
help
man OOO
curl -help
telnet localhost 8000
*/