-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (50 loc) · 1.37 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
var test_print = require("./tests/index");
var test_exports = require("./tests/shape");
var http = require('http');
var child_process = require('child_process');
var startServer = require('./server');
var async_demo = require('./tests/async_demo');
var _ = require('underscore');
var fs = require('fs');
var data= {
name:"merlin",
age:20
}
function testModuleExports() {
test_print("world");
console.log(test_exports.hello());
}
function testProcessArgv() {
console.log(" prcess argv 0:"+process.argv[0]);
console.log(" prcess argv 1:"+process.argv[1]);
}
function testServerClient() {
startServer();
var child = child_process.spawn('node',['./client.js'], {
stdio:[0,1,2,'ipc']
});
// the other wat to access child process stdout
// child.stdout.on('data', function (data) {
// console.log('stdout: ' + data);
// });
//
// child.stderr.on('data', function (data) {
// console.log('stderr: ' + data);
// });
//
//
child.on('close', function (code) {
console.log('child process exited with code ' + code);
});
child.on('message', function(msg) {
console.log("the cliend said : " + msg.hello);
// process.exit(0);
});
child.send({hello:'hello client!'});
}
//testProcessArgv();
//async_demo();
//testServerClient();
fs.writeFile('./data.json',JSON.stringify(data),function(err,callback) {
if(err) {callback(err)}
});