forked from iwillwen/webjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsayhello.js
executable file
·57 lines (43 loc) · 995 Bytes
/
sayhello.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
var http = require('http');
var web = require('./index.js');
function ask()
{
var req = http.request({
host: '127.0.0.1',
port: '45678',
path: '/getQuerystring',
method: 'get'
});
req.on('response',function(res){
res.on('data',function(chunk){
console.log('body:' + chunk);
})
});
req.end();
}
var getRouter = {
'name\/(.*)': function (req, res) {
res.send('Hey! Mr. ' + decodeURI(req.path[0]) + '! Nice to meet you.');
},
'getQuerystring' : function (req, res) {
res.sendJSON('querystring');
}
};
web.run({}, 45678);
ask();
setTimeout(function(){
web.get(getRouter);
ask();
},3000);
var util = require('util'),
spawn = require('child_process').spawn,
ls = spawn('ls', ['-lh', '/usr']);
ls.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
ls.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
ls.on('exit', function (code) {
console.log('child process exited with code ' + code);
});