port = parseInt(process.env.PORT || 8000);
-var puts = require("sys").puts;
+var console.log = require("sys").console.log;
var old = (process.argv[2] == 'old');
-puts('pid ' + process.pid);
+console.log('pid ' + process.pid);
http = require(old ? "http_old" : 'http');
-if (old) puts('old version');
+if (old) console.log('old version');
fixed = ""
for (var i = 0; i < 20*1024; i++) {
if (n <= 0)
throw "bytes called with n <= 0"
if (stored[n] === undefined) {
- puts("create stored[n]");
+ console.log("create stored[n]");
stored[n] = "";
for (var i = 0; i < n; i++) {
stored[n] += "C"
var n = parseInt(arg, 10)
if (n <= 0) throw new Error("bytes called with n <= 0");
if (storedBuffer[n] === undefined) {
- puts("create storedBuffer[n]");
+ console.log("create storedBuffer[n]");
storedBuffer[n] = new Buffer(n);
for (var i = 0; i < n; i++) {
storedBuffer[n][i] = "C".charCodeAt(0);
}
}).listen(port);
-puts('Listening at http://127.0.0.1:'+port+'/');
+console.log('Listening at http://127.0.0.1:'+port+'/');
sys.print(benchmarks[i] + ": ");
exec(benchmarks[i], function (elapsed, code) {
if (code != 0) {
- sys.puts("ERROR ");
+ console.log("ERROR ");
}
- sys.puts(elapsed);
+ console.log(elapsed);
runNext(i+1);
});
};
#!/usr/bin/env node
-var puts = require("sys").puts;
-
-puts("Type '.help' for options.");
-puts("(The REPL can also be started by typing 'node' without arguments)");
+console.log("Type '.help' for options.");
+console.log("(The REPL can also be started by typing 'node' without arguments)");
require('repl').start();
An example of a web server written with Node which responds with 'Hello
World':
- var sys = require('sys'),
- http = require('http');
+ var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8124);
- sys.puts('Server running at http://127.0.0.1:8124/');
+ console.log('Server running at http://127.0.0.1:8124/');
To run the server, put the code into a file called `example.js` and execute
it with the node program
Example: write a utf8 string into a buffer, then print it
- var sys = require('sys'),
- Buffer = require('buffer').Buffer,
+ var Buffer = require('buffer').Buffer,
buf = new Buffer(256),
len;
len = buf.write('\u00bd + \u00bc = \u00be', 'utf8', 0);
- sys.puts(len + " bytes: " + buf.toString('utf8', 0, len));
+ console.log(len + " bytes: " + buf.toString('utf8', 0, len));
// 12 bytes: ½ + ¼ = ¾
Example: copy an ASCII string into a buffer, one byte at a time:
- var sys = require('sys'),
- Buffer = require('buffer').Buffer,
+ var Buffer = require('buffer').Buffer,
str = "node.js",
buf = new Buffer(str.length),
i;
buf[i] = str.charCodeAt(i);
}
- sys.puts(buf);
+ console.log(buf);
// node.js
Example:
- var sys = require('sys'),
- Buffer = require('buffer').Buffer,
+ var Buffer = require('buffer').Buffer,
str = '\u00bd + \u00bc = \u00be';
- sys.puts(str + ": " + str.length + " characters, " +
+ console.log(str + ": " + str.length + " characters, " +
Buffer.byteLength(str, 'utf8') + " bytes");
// ½ + ¼ = ¾: 9 characters, 12 bytes
of the contents. `length` refers to the amount of memory allocated for the
buffer object. It does not change when the contents of the buffer are changed.
- var sys = require('sys'),
- Buffer = require('buffer').Buffer,
+ var Buffer = require('buffer').Buffer,
buf = new Buffer(1234);
- sys.puts(buf.length);
+ console.log(buf.length);
buf.write("some string", "ascii", 0);
- sys.puts(buf.length);
+ console.log(buf.length);
// 1234
// 1234
Example: build two Buffers, then copy `buf1` from byte 16 through byte 20
into `buf2`, starting at the 8th byte in `buf2`.
- var sys = require('sys'),
- Buffer = require('buffer').Buffer,
+ var Buffer = require('buffer').Buffer,
buf1 = new Buffer(26),
buf2 = new Buffer(26),
i;
}
buf1.copy(buf2, 8, 16, 20);
- sys.puts(buf2.toString('ascii', 0, 25));
+ console.log(buf2.toString('ascii', 0, 25));
// !!!!!!!!qrst!!!!!!!!!!!!!
Example: build a Buffer with the ASCII alphabet, take a slice, then modify one byte
from the original Buffer.
- var sys = require('sys'),
- Buffer = require('buffer').Buffer,
+ var Buffer = require('buffer').Buffer,
buf1 = new Buffer(26), buf2,
i;
}
buf2 = buf1.slice(0, 3);
- sys.puts(buf2.toString('ascii', 0, buf2.length));
+ console.log(buf2.toString('ascii', 0, buf2.length));
buf1[0] = 33;
- sys.puts(buf2.toString('ascii', 0, buf2.length));
+ console.log(buf2.toString('ascii', 0, buf2.length));
// abc
// !bc
Adds a listener to the end of the listeners array for the specified event.
server.addListener('stream', function (stream) {
- sys.puts('someone connected!');
+ console.log('someone connected!');
});
Example: add a new path to the beginning of the search list
- var sys = require('sys');
-
require.paths.unshift('/usr/local/node');
- sys.puts(require.paths);
+ console.log(require.paths);
// /usr/local/node,/Users/mjr/.node_libraries
Example: running `node example.js` from `/Users/mjr`
- var sys = require('sys');
- sys.puts(__filename);
- sys.puts(__dirname);
+ console.log(__filename);
+ console.log(__dirname);
// /Users/mjr/example.js
// /Users/mjr
Example of listening for `exit`:
- var sys = require('sys');
-
process.addListener('exit', function () {
process.nextTick(function () {
- sys.puts('This will not run');
+ console.log('This will not run');
});
- sys.puts('About to exit.');
+ console.log('About to exit.');
});
### Event: 'uncaughtException'
Example of listening for `uncaughtException`:
- var sys = require('sys');
-
process.addListener('uncaughtException', function (err) {
- sys.puts('Caught exception: ' + err);
+ console.log('Caught exception: ' + err);
});
setTimeout(function () {
- sys.puts('This will still run.');
+ console.log('This will still run.');
}, 500);
// Intentionally cause an exception, but don't catch it.
nonexistentFunc();
- sys.puts('This will not run.');
+ console.log('This will not run.');
Note that `uncaughtException` is a very crude mechanism for exception
handling. Using try / catch in your program will give you more control over
Example of listening for `SIGINT`:
- var sys = require('sys'),
- stdin = process.openStdin();
+ var stdin = process.openStdin();
process.addListener('SIGINT', function () {
- sys.puts('Got SIGINT. Press Control-D to exit.');
+ console.log('Got SIGINT. Press Control-D to exit.');
});
An easy way to send the `SIGINT` signal is with `Control-C` in most terminal
A writable stream to `stdout`.
-Example: the definition of `sys.puts`
+Example: the definition of `console.log`
- exports.puts = function (d) {
+ console.log = function (d) {
process.stdout.write(d + '\n');
};
next elements will be any additional command line arguments.
// print process.argv
- var sys = require('sys');
-
process.argv.forEach(function (val, index, array) {
- sys.puts(index + ': ' + val);
+ console.log(index + ': ' + val);
});
This will generate:
Changes the current working directory of the process or throws an exception if that fails.
- var sys = require('sys');
-
- sys.puts('Starting directory: ' + process.cwd());
+ console.log('Starting directory: ' + process.cwd());
try {
process.chdir('/tmp');
- sys.puts('New directory: ' + process.cwd());
+ console.log('New directory: ' + process.cwd());
}
catch (err) {
- sys.puts('chdir: ' + err);
+ console.log('chdir: ' + err);
}
Example of using `process.compile` and `eval` to run the same code:
- var sys = require('sys'),
- localVar = 123,
+ var localVar = 123,
compiled, evaled;
compiled = process.compile('localVar = 1;', 'myfile.js');
- sys.puts('localVar: ' + localVar + ', compiled: ' + compiled);
+ console.log('localVar: ' + localVar + ', compiled: ' + compiled);
evaled = eval('localVar = 1;');
- sys.puts('localVar: ' + localVar + ', evaled: ' + evaled);
+ console.log('localVar: ' + localVar + ', evaled: ' + evaled);
// localVar: 123, compiled: 1
// localVar: 1, evaled: 1
Returns the current working directory of the process.
- require('sys').puts('Current directory: ' + process.cwd());
+ console.log('Current directory: ' + process.cwd());
### process.env
Gets/sets the group identity of the process. (See setgid(2).) This is the numerical group id, not the group name.
- var sys = require('sys');
-
- sys.puts('Current gid: ' + process.getgid());
+ console.log('Current gid: ' + process.getgid());
try {
process.setgid(501);
- sys.puts('New gid: ' + process.getgid());
+ console.log('New gid: ' + process.getgid());
}
catch (err) {
- sys.puts('Failed to set gid: ' + err);
+ console.log('Failed to set gid: ' + err);
}
Gets/sets the user identity of the process. (See setuid(2).) This is the numerical userid, not the username.
- var sys = require('sys');
-
- sys.puts('Current uid: ' + process.getuid());
+ console.log('Current uid: ' + process.getuid());
try {
process.setuid(501);
- sys.puts('New uid: ' + process.getuid());
+ console.log('New uid: ' + process.getuid());
}
catch (err) {
- sys.puts('Failed to set uid: ' + err);
+ console.log('Failed to set uid: ' + err);
}
A compiled-in property that exposes `NODE_VERSION`.
- require('sys').puts('Version: ' + process.version);
+ console.log('Version: ' + process.version);
### process.installPrefix
A compiled-in property that exposes `NODE_PREFIX`.
- require('sys').puts('Prefix: ' + process.installPrefix);
+ console.log('Prefix: ' + process.installPrefix);
### process.kill(pid, signal)
Example of sending a signal to yourself:
- var sys = require('sys');
-
process.addListener('SIGHUP', function () {
- sys.puts('Got SIGHUP signal.');
+ console.log('Got SIGHUP signal.');
});
setTimeout(function () {
- sys.puts('Exiting.');
+ console.log('Exiting.');
process.exit(0);
}, 100);
The PID of the process.
- require('sys').puts('This process is pid ' + process.pid);
+ console.log('This process is pid ' + process.pid);
### process.platform
What platform you're running on. `'linux2'`, `'darwin'`, etc.
- require('sys').puts('This platform is ' + process.platform);
+ console.log('This platform is ' + process.platform);
### process.memoryUsage()
var sys = require('sys');
- sys.puts(sys.inspect(process.memoryUsage()));
+ console.log(sys.inspect(process.memoryUsage()));
This will generate:
This is *not* a simple alias to `setTimeout(fn, 0)`, it's much more
efficient.
- var sys = require('sys');
-
process.nextTick(function () {
- sys.puts('nextTick callback');
+ console.log('nextTick callback');
});
the mask from the parent process. Returns the old mask if `mask` argument is
given, otherwise returns the current mask.
- var sys = require('sys'),
- oldmask, newmask = 0644;
+ var oldmask, newmask = 0644;
oldmask = process.umask(newmask);
- sys.puts('Changed umask from: ' + oldmask.toString(8) +
- ' to ' + newmask.toString(8));
+ console.log('Changed umask from: ' + oldmask.toString(8) +
+ ' to ' + newmask.toString(8));
them.
-### sys.puts(string)
-
-Outputs `string` and a trailing newline to `stdout`.
-
- require('sys').puts('String with a newline');
-
-
### sys.print(string)
-Like `puts()` but without the trailing newline.
+Like `console.log()` but without the trailing newline.
require('sys').print('String with no newline');
var sys = require('sys');
- sys.puts(sys.inspect(sys, true, null));
+ console.log(sys.inspect(sys, true, null));
### sys.pump(readableStream, writeableStream, [callback])
});
ls.addListener('exit', function (code) {
- sys.puts('child process exited with code ' + code);
+ console.log('child process exited with code ' + code);
});
Example of checking for failed exec:
- var sys = require('sys'),
- spawn = require('child_process').spawn,
+ var spawn = require('child_process').spawn,
child = spawn('bad_command');
child.stderr.addListener('data', function (data) {
if (/^execvp\(\)/.test(data.asciiSlice(0,data.length))) {
- sys.puts('Failed to start child process.');
+ console.log('Failed to start child process.');
}
});
Send a signal to the child process. If no argument is given, the process will
be sent `'SIGTERM'`. See `signal(7)` for a list of available signals.
- var sys = require('sys'),
- spawn = require('child_process').spawn,
+ var spawn = require('child_process').spawn,
grep = spawn('grep', ['ssh']);
grep.addListener('exit', function (code, signal) {
- sys.puts('child process terminated due to receipt of signal '+signal);
+ console.log('child process terminated due to receipt of signal '+signal);
});
// send SIGHUP to process
Example:
- var sys = require('sys'),
- spawn = require('child_process').spawn,
+ var spawn = require('child_process').spawn,
grep = spawn('grep', ['ssh']);
- sys.puts('Spawned child pid: ' + grep.pid);
+ console.log('Spawned child pid: ' + grep.pid);
grep.stdin.end();
ps.addListener('exit', function (code) {
if (code !== 0) {
- sys.puts('ps process exited with code ' + code);
+ console.log('ps process exited with code ' + code);
}
grep.stdin.end();
});
grep.addListener('exit', function (code) {
if (code !== 0) {
- sys.puts('grep process exited with code ' + code);
+ console.log('grep process exited with code ' + code);
}
});
Example:
- var sys = require('sys'),
- spawn = require('child_process').spawn,
+ var spawn = require('child_process').spawn,
grep = spawn('grep', ['ssh']);
grep.addListener('exit', function (code) {
- sys.puts('child process exited with code ' + code);
+ console.log('child process exited with code ' + code);
});
grep.stdin.end();
sys.print('stdout: ' + stdout);
sys.print('stderr: ' + stderr);
if (error !== null) {
- sys.puts('exec error: ' + error);
+ console.log('exec error: ' + error);
}
});
Example of using `Script.runInThisContext` and `eval` to run the same code:
- var sys = require('sys'),
- localVar = 123,
+ var localVar = 123,
usingscript, evaled,
Script = process.binding('evals').Script;
usingscript = Script.runInThisContext('localVar = 1;',
'myfile.js');
- sys.puts('localVar: ' + localVar + ', usingscript: ' +
+ console.log('localVar: ' + localVar + ', usingscript: ' +
usingscript);
evaled = eval('localVar = 1;');
- sys.puts('localVar: ' + localVar + ', evaled: ' +
+ console.log('localVar: ' + localVar + ', evaled: ' +
evaled);
// localVar: 123, usingscript: 1
Script.runInNewContext(
'count += 1; name = "kitty"', sandbox, 'myfile.js');
- sys.puts(sys.inspect(sandbox));
+ console.log(sys.inspect(sandbox));
// { animal: 'cat', count: 3, name: 'kitty' }
Example of using `script.runInThisContext` to compile code once and run it multiple times:
- var sys = require('sys'),
- Script = process.binding('evals').Script,
+ var Script = process.binding('evals').Script,
scriptObj, i;
globalVar = 0;
scriptObj.runInThisContext();
}
- sys.puts(globalVar);
+ console.log(globalVar);
// 1000
scriptObj.runInNewContext(sandbox);
}
- sys.puts(sys.inspect(sandbox));
+ console.log(sys.inspect(sandbox));
// { animal: 'cat', count: 12, name: 'kitty' }
Here is an example of the asynchronous version:
- var fs = require('fs'),
- sys = require('sys');
+ var fs = require('fs');
fs.unlink('/tmp/hello', function (err) {
if (err) throw err;
- sys.puts('successfully deleted /tmp/hello');
+ console.log('successfully deleted /tmp/hello');
});
Here is the synchronous version:
- var fs = require('fs'),
- sys = require('sys');
+ var fs = require('fs');
fs.unlinkSync('/tmp/hello')
- sys.puts('successfully deleted /tmp/hello');
+ console.log('successfully deleted /tmp/hello');
With the asynchronous methods there is no guaranteed ordering. So the
following is prone to error:
fs.rename('/tmp/hello', '/tmp/world', function (err) {
if (err) throw err;
- sys.puts('renamed complete');
+ console.log('renamed complete');
});
fs.stat('/tmp/world', function (err, stats) {
if (err) throw err;
- sys.puts('stats: ' + JSON.stringify(stats));
+ console.log('stats: ' + JSON.stringify(stats));
});
It could be that `fs.stat` is executed before `fs.rename`.
if (err) throw err;
fs.stat('/tmp/world', function (err, stats) {
if (err) throw err;
- sys.puts('stats: ' + JSON.stringify(stats));
+ console.log('stats: ' + JSON.stringify(stats));
});
});
fs.readFile('/etc/passwd', function (err, data) {
if (err) throw err;
- sys.puts(data);
+ console.log(data);
});
The callback is passed two arguments `(err, data)`, where `data` is the
fs.writeFile('message.txt', 'Hello Node', function (err) {
if (err) throw err;
- sys.puts('It\'s saved!');
+ console.log('It\'s saved!');
});
### fs.writeFileSync(filename, data, encoding='utf8')
stat object:
fs.watchFile(f, function (curr, prev) {
- sys.puts('the current mtime is: ' + curr.mtime);
- sys.puts('the previous mtime was: ' + prev.mtime);
+ console.log('the current mtime is: ' + curr.mtime);
+ console.log('the previous mtime was: ' + prev.mtime);
});
These stat objects are instances of `fs.Stat`.
Example of connecting to `google.com`:
- var sys = require('sys'),
- http = require('http');
+ var http = require('http');
var google = http.createClient(80, 'www.google.com');
var request = google.request('GET', '/',
{'host': 'www.google.com'});
request.end();
request.addListener('response', function (response) {
- sys.puts('STATUS: ' + response.statusCode);
- sys.puts('HEADERS: ' + JSON.stringify(response.headers));
+ console.log('STATUS: ' + response.statusCode);
+ console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
response.addListener('data', function (chunk) {
- sys.puts('BODY: ' + chunk);
+ console.log('BODY: ' + chunk);
});
});
// Good
request.addListener('response', function (response) {
response.addListener('data', function (chunk) {
- sys.puts('BODY: ' + chunk);
+ console.log('BODY: ' + chunk);
});
});
request.addListener('response', function (response) {
setTimeout(function () {
response.addListener('data', function (chunk) {
- sys.puts('BODY: ' + chunk);
+ console.log('BODY: ' + chunk);
});
}, 10);
});
Here is an example which resolves `'www.google.com'` then reverse
resolves the IP addresses which are returned.
- var dns = require('dns'),
- sys = require('sys');
+ var dns = require('dns');
dns.resolve4('www.google.com', function (err, addresses) {
if (err) throw err;
- sys.puts('addresses: ' + JSON.stringify(addresses));
+ console.log('addresses: ' + JSON.stringify(addresses));
for (var i = 0; i < addresses.length; i++) {
var a = addresses[i];
dns.reverse(a, function (err, domains) {
if (err) {
- sys.puts('reverse for ' + a + ' failed: ' +
+ console.log('reverse for ' + a + ' failed: ' +
err.message);
} else {
- sys.puts('reverse for ' + a + ': ' +
+ console.log('reverse for ' + a + ': ' +
JSON.stringify(domains));
}
});
node> a = [ 1, 2, 3];
[ 1, 2, 3 ]
node> a.forEach(function (v) {
- ... sys.puts(v);
+ ... console.log(v);
... });
1
2
Here is an example that starts a REPL on stdin, a Unix socket, and a TCP socket:
- var sys = require("sys"),
- net = require("net"),
+ var net = require("net"),
repl = require("repl");
connections = 0;
The contents of `foo.js`:
- var circle = require('./circle'),
- sys = require('sys');
- sys.puts( 'The area of a circle of radius 4 is '
- + circle.area(4));
+ var circle = require('./circle');
+ console.log( 'The area of a circle of radius 4 is '
+ + circle.area(4));
The contents of `circle.js`:
</p>
<pre>
-var sys = require('sys'),
- http = require('http');
+var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(8124, "127.0.0.1");
-sys.puts('Server running at http://127.0.0.1:8124/');
+console.log('Server running at http://127.0.0.1:8124/');
</pre>
<p>
};
+global.console = {};
+
+global.console.log = function (x) {
+ process.stdout.write(x + '\n');
+};
+
+
process.exit = function (code) {
process.emit("exit");
process.reallyExit(code);
} else {
// No arguments, run the repl
var repl = module.requireNative('repl');
- process.stdout.write("Type '.help' for options.\n");
+ console.log("Type '.help' for options.");
repl.start();
}
require("../common.js");
http = require("/http.js");
-puts("hello world");
+console.log("hello world");
var body = "exports.A = function() { return 'A';}";
var server = http.createServer(function (req, res) {
- puts("req?");
+ console.log("req?");
res.sendHeader(200, {
"Content-Length": body.length,
"Content-Type": "text/plain"
if (expected.length == 1 && expected[0] == '3(NXDOMAIN)' && result.length == 0) {
// it's ok, dig returns NXDOMAIN, while dns module returns nothing
} else {
- puts('---WARNING---\nexpected ' + expected + '\nresult ' + result + '\n-------------');
+ console.log('---WARNING---\nexpected ' + expected + '\nresult ' + result + '\n-------------');
}
return;
}
ll = expected.length;
while (ll--) {
assert.equal(result[ll], expected[ll]);
- puts("Result " + result[ll] + " was equal to expected " + expected[ll]);
+ console.log("Result " + result[ll] + " was equal to expected " + expected[ll]);
}
}
require("../common");
-puts('first stat ...');
+console.log('first stat ...');
fs.stat(__filename)
.addCallback( function(stats) {
- puts('second stat ...');
+ console.log('second stat ...');
fs.stat(__filename)
.timeout(1000)
.wait();
- puts('test passed');
+ console.log('test passed');
})
.addErrback(function() {
throw new Exception();
c.addListener('error', function (e) {
- puts('proxy client error. sent ' + sent);
+ console.log('proxy client error. sent ' + sent);
throw e;
});
req.end();
} else {
- sys.puts("End of list. closing servers");
+ console.log("End of list. closing servers");
proxy.close();
chargen.close();
done = true;
res.writeHeader(200 , { 'Content-Length': body.length.toString()
, 'Content-Type': 'text/plain'
});
- sys.puts('method: ' + req.method);
+ console.log('method: ' + req.method);
if (req.method != 'HEAD') res.write(body);
res.end();
});
var client = http.createClient(PORT);
var request = client.request("HEAD", "/");
request.addListener('response', function (response) {
- sys.puts('got response');
+ console.log('got response');
response.addListener("data", function () {
process.exit(2);
});
requests_ok++;
}
if (requests_complete == request_count) {
- puts("\nrequests ok: " + requests_ok);
+ console.log("\nrequests ok: " + requests_ok);
server.close();
}
});
sys.exec(cmd, function (err, stdout, stderr) {
if (err) throw err;
- puts('success!');
+ console.log('success!');
modulesLoaded++;
server.close();
});
client.setEncoding("UTF8");
client.addListener("connect", function () {
- sys.puts("client connected.");
+ console.log("client connected.");
client.setSecure(credentials);
});
client.addListener("secure", function () {
- sys.puts("client secure : "+JSON.stringify(client.getCipher()));
- sys.puts(JSON.stringify(client.getPeerCertificate()));
- sys.puts("verifyPeer : "+client.verifyPeer());
+ console.log("client secure : "+JSON.stringify(client.getCipher()));
+ console.log(JSON.stringify(client.getPeerCertificate()));
+ console.log("verifyPeer : "+client.verifyPeer());
client.write("GET / HTTP/1.0\r\n\r\n");
});
});
client.addListener("end", function () {
- sys.puts("client disconnected.");
+ console.log("client disconnected.");
});
connection.setEncoding("binary");
connection.addListener("secure", function () {
- //sys.puts("Secure");
+ //console.log("Secure");
});
connection.addListener("data", function (chunk) {
- sys.puts("recved: " + JSON.stringify(chunk));
+ console.log("recved: " + JSON.stringify(chunk));
connection.write("HTTP/1.0 200 OK\r\nContent-type: text/plain\r\nContent-length: 9\r\n\r\nOK : "+i+"\r\n\r\n");
i=i+1;
connection.end();
process.addListener("exit", function () {
string = "C done";
- puts("b/c.js exit");
+ console.log("b/c.js exit");
});
[0, 1].forEach(function(i) {
exec('ls', function(err, stdout, stderr) {
- puts(i);
+ console.log(i);
throw new Error('hello world');
});
});
exports.hello = function () {
return root.calledFromFoo();
-};
\ No newline at end of file
+};
};
exports.calledFromFoo = function () {
return exports.hello;
-};
\ No newline at end of file
+};
-process.exit(process.argv[2] || 1);
\ No newline at end of file
+process.exit(process.argv[2] || 1);
puts = require('sys').puts;
for (var i = 0; i < 10; i++) {
- puts('count ' + i);
+ console.log('count ' + i);
}
require('../common');
sys = require('sys');
-sys.puts([
+console.log([
'_______________________________________________50',
'______________________________________________100',
'______________________________________________150',
require('../common');
-puts('hello world');
+console.log('hello world');
ReferenceError: foo is not defined
at evalmachine.<anonymous>:1:1
at Object.<anonymous> (*test/message/undefined_reference_in_new_context.js:9:8)
- at Module._compile (module:384:23)
- at Module._loadScriptSync (module:393:8)
- at Module.loadSync (module:296:10)
- at Object.runMain (module:447:22)
- at node.js:208:10
+ at Module._compile (module:*:23)
+ at Module._loadScriptSync (module:*:8)
+ at Module.loadSync (module:*:*)
+ at Object.runMain (module:*:*)
+ at node.js:*:*
});
child.stderr.addListener("data", function (chunk) {
- puts('stderr: ' + chunk);
+ console.log('stderr: ' + chunk);
});
child.addListener("exit", function () {
var client = http.createClient(PORT);
client.addListener("error", function() {
- sys.puts("ERROR!");
+ console.log("ERROR!");
errorCount++;
});
client.addListener("end", function() {
- sys.puts("EOF!");
+ console.log("EOF!");
eofCount++;
});
var request = client.request("GET", "/", {"host": "localhost"});
request.end();
request.addListener('response', function(response) {
- sys.puts("STATUS: " + response.statusCode);
+ console.log("STATUS: " + response.statusCode);
});
setTimeout(function () {
var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/";
exec(command, function (err, stdout, stderr) {
if (err) {
- puts("ab not installed? skipping test.\n" + stderr);
+ console.log("ab not installed? skipping test.\n" + stderr);
process.exit();
return;
}
runAb("-k -c 100 -t 2", function (reqSec, keepAliveRequests) {
keepAliveReqSec = reqSec;
assert.equal(true, keepAliveRequests > 0);
- puts("keep-alive: " + keepAliveReqSec + " req/sec");
+ console.log("keep-alive: " + keepAliveReqSec + " req/sec");
runAb("-c 100 -t 2", function (reqSec, keepAliveRequests) {
normalReqSec = reqSec;
assert.equal(0, keepAliveRequests);
- puts("normal: " + normalReqSec + " req/sec");
+ console.log("normal: " + normalReqSec + " req/sec");
server.close();
});
});
});
client.addListener("error", function (e) {
- puts("\n\nERROOOOOr");
+ console.log("\n\nERROOOOOr");
throw e;
});
assert.equal(bytes, client.recved.length);
if (client.fd) {
- puts(client.fd);
+ console.log(client.fd);
}
assert.ok(!client.fd);
process.addListener("exit", function () {
assert.equal(connections_per_client * concurrency, total_connections);
- puts("\nokay!");
+ console.log("\nokay!");
});
setTimeout(function () {
chars_recved = recv.length;
- puts("pause at: " + chars_recved);
+ console.log("pause at: " + chars_recved);
assert.equal(true, chars_recved > 1);
client.pause();
setTimeout(function () {
- puts("resume at: " + chars_recved);
+ console.log("resume at: " + chars_recved);
assert.equal(chars_recved, recv.length);
client.resume();
setTimeout(function () {
chars_recved = recv.length;
- puts("pause at: " + chars_recved);
+ console.log("pause at: " + chars_recved);
client.pause();
setTimeout(function () {
- puts("resume at: " + chars_recved);
+ console.log("resume at: " + chars_recved);
assert.equal(chars_recved, recv.length);
client.resume();
socket.setEncoding("utf8");
socket.addListener("data", function (data) {
- puts(data);
+ console.log(data);
assert.equal("PING", data);
assert.equal("open", socket.readyState);
assert.equal(true, count <= N);
});
socket.addListener("end", function () {
- puts("server-side socket EOF");
+ console.log("server-side socket EOF");
assert.equal("writeOnly", socket.readyState);
socket.end();
});
socket.addListener("close", function (had_error) {
- puts("server-side socket.end");
+ console.log("server-side socket.end");
assert.equal(false, had_error);
assert.equal("closed", socket.readyState);
socket.server.close();
});
client.addListener("data", function (data) {
- puts(data);
+ console.log(data);
assert.equal("PONG", data);
assert.equal("open", client.readyState);
if (count++ < N) {
client.write("PING");
} else {
- puts("closing client");
+ console.log("closing client");
client.end();
client_ended = true;
}
});
client.addListener("close", function () {
- puts("client.end");
+ console.log("client.end");
assert.equal(N+1, count);
assert.ok(client_ended);
if (on_complete) on_complete();
if (host === "127.0.0.1" || host === "localhost" || !host) {
assert.equal(socket.remoteAddress, "127.0.0.1");
} else {
- puts('host = ' + host + ', remoteAddress = ' + socket.remoteAddress);
+ console.log('host = ' + host + ', remoteAddress = ' + socket.remoteAddress);
assert.equal(socket.remoteAddress, "::1");
}
socket.timeout = 0;
socket.addListener("data", function (data) {
- puts("server got: " + JSON.stringify(data));
+ console.log("server got: " + JSON.stringify(data));
assert.equal("open", socket.readyState);
assert.equal(true, count <= N);
if (/PING/.exec(data)) {
});
client.addListener("data", function (data) {
- puts('client got: ' + data);
+ console.log('client got: ' + data);
assert.equal("PONG", data);
count += 1;
net = require("net");
N = 160*1024; // 30kb
-puts("build big string");
+console.log("build big string");
var body = "";
for (var i = 0; i < N; i++) {
body += "C";
}
-puts("start server on port " + PORT);
+console.log("start server on port " + PORT);
server = net.createServer(function (connection) {
connection.addListener("connect", function () {
client.setEncoding("ascii");
client.addListener("data", function (d) {
chars_recved += d.length;
- puts("got " + chars_recved);
+ console.log("got " + chars_recved);
if (!paused) {
client.pause();
npauses += 1;
paused = true;
- puts("pause");
+ console.log("pause");
x = chars_recved;
setTimeout(function () {
assert.equal(chars_recved, x);
client.resume();
- puts("resume");
+ console.log("resume");
paused = false;
}, 100);
}
socket.setTimeout(timeout);
socket.addListener("timeout", function () {
- puts("server timeout");
+ console.log("server timeout");
timeouttime = new Date;
p(timeouttime);
socket.destroy();
})
socket.addListener("data", function (d) {
- puts(d);
+ console.log(d);
socket.write(d);
});
});
echo_server.listen(PORT, function () {
- puts("server listening at " + PORT);
+ console.log("server listening at " + PORT);
});
var client = net.createConnection(PORT);
client.setEncoding("UTF8");
client.setTimeout(0); // disable the timeout for client
client.addListener("connect", function () {
- puts("client connected.");
+ console.log("client connected.");
client.write("hello\r\n");
});
assert.equal("hello\r\n", chunk);
if (exchanges++ < 5) {
setTimeout(function () {
- puts("client write 'hello'");
+ console.log("client write 'hello'");
client.write("hello\r\n");
}, 500);
if (exchanges == 5) {
- puts("wait for timeout - should come in " + timeout + " ms");
+ console.log("wait for timeout - should come in " + timeout + " ms");
starttime = new Date;
p(starttime);
}
});
client.addListener("end", function () {
- puts("client end");
+ console.log("client end");
client.end();
});
client.addListener("close", function () {
- puts("client disconnect");
+ console.log("client disconnect");
echo_server.close();
});
assert.ok(timeouttime != null);
diff = timeouttime - starttime;
- puts("diff = " + diff);
+ console.log("diff = " + diff);
assert.ok(timeout < diff);
assert.equal(verified, 1);
assert.equal(peerDN, "C=UK,ST=Acknack Ltd,L=Rhys Jones,O=node.js,"
+ "OU=Test TLS Certificate,CN=localhost");
- puts("server got: " + JSON.stringify(data));
+ console.log("server got: " + JSON.stringify(data));
assert.equal("open", socket.readyState);
assert.equal(true, count <= N);
if (/PING/.exec(data)) {
assert.equal("PONG", data);
count += 1;
- puts("client got PONG");
+ console.log("client got PONG");
if (sent_final_ping) {
assert.equal("readOnly", client.readyState);
assert.equal(2, tests_run);
});
} else {
- puts("Not compiled with TLS support -- skipping test");
+ console.log("Not compiled with TLS support -- skipping test");
process.exit(0);
}
var diff = endtime - starttime;
assert.ok(diff > 0);
- puts("diff: " + diff);
+ console.log("diff: " + diff);
assert.equal(true, 1000 - WINDOW < diff && diff < 1000 + WINDOW);
setTimeout_called = true;
var diff = endtime - starttime;
assert.ok(diff > 0);
- puts("diff: " + diff);
+ console.log("diff: " + diff);
var t = interval_count * 1000;
var f = path.join(fixturesDir, "x.txt");
var f2 = path.join(fixturesDir, "x2.txt");
-puts("watching for changes of " + f);
+console.log("watching for changes of " + f);
var changes = 0;
function watchFile () {
fs.watchFile(f, function (curr, prev) {
- puts(f + " change");
+ console.log(f + " change");
changes++;
assert.ok(curr.mtime != prev.mtime);
fs.unwatchFile(f);
var b = new Buffer(1024);
-puts("b.length == " + b.length);
+console.log("b.length == " + b.length);
assert.equal(1024, b.length);
for (var i = 0; i < 1024; i++) {
var testValue = '\u00F6\u65E5\u672C\u8A9E'; // ö日本語
var buffer = new Buffer(32);
var size = buffer.utf8Write(testValue, 0);
-puts('bytes written to buffer: ' + size);
+console.log('bytes written to buffer: ' + size);
var slice = buffer.toString('utf8', 0, size);
assert.equal(slice, testValue);
assert.deepEqual(e, new Buffer([195, 188, 98, 101, 114]));
var f = new Buffer('über', 'ascii');
-assert.deepEqual(f, new Buffer([252, 98, 101, 114]));
\ No newline at end of file
+assert.deepEqual(f, new Buffer([252, 98, 101, 114]));
child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (s) {
- puts("stdout: " + JSON.stringify(s));
+ console.log("stdout: " + JSON.stringify(s));
output += s;
});
child.addListener("exit", function (c) {
- puts("exit: " + c);
+ console.log("exit: " + c);
assert.equal(0, c);
callback(output);
pwd_called = true;
var helloPath = fixtPath("hello.txt");
function test1(next) {
- puts("Test 1...");
+ console.log("Test 1...");
fs.open(helloPath, 'w', 400, function (err, fd) {
if (err) throw err;
var child = spawn('/bin/echo', [expected], undefined, [-1, fd] );
fs.readFile(helloPath, function (err, data) {
if (err) throw err;
assert.equal(data.toString(), expected + "\n");
- puts(' File was written.');
+ console.log(' File was written.');
next(test3);
});
});
// Test the equivalent of:
// $ node ../fixture/stdio-filter.js < hello.txt
function test2(next) {
- puts("Test 2...");
+ console.log("Test 2...");
fs.open(helloPath, 'r', undefined, function (err, fd) {
var child = spawn(process.argv[0]
, [fixtPath('stdio-filter.js'), 'o', 'a']
child.addListener('exit', function (code) {
if (err) throw err;
assert.equal(actualData, "hella warld\n");
- puts(" File was filtered successfully");
+ console.log(" File was filtered successfully");
fs.close(fd, function () {
next(test3);
});
// Test the equivalent of:
// $ /bin/echo "hello world" | ../stdio-filter.js a o
function test3(next) {
- puts("Test 3...");
+ console.log("Test 3...");
var filter = spawn(process.argv[0]
, [fixtPath('stdio-filter.js'), 'o', 'a']);
var echo = spawn('/bin/echo', [expected], undefined, [-1, filter.fds[0]]);
var actualData = '';
filter.stdout.addListener('data', function(data) {
- puts(" Got data --> " + data);
+ console.log(" Got data --> " + data);
actualData += data;
});
filter.addListener('exit', function(code) {
if (code) throw "Return code was " + code;
assert.equal(actualData, "hella warld\n");
- puts(" Talked to another process successfully");
+ console.log(" Talked to another process successfully");
});
echo.addListener('exit', function(code) {
if (code) throw "Return code was " + code;
});
}
-test1(test2);
\ No newline at end of file
+test1(test2);
child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (chunk) {
- puts("stdout: " + chunk);
+ console.log("stdout: " + chunk);
response += chunk;
});
var child = spawn(process.argv[0], [sub]);
child.stderr.addListener("data", function (data){
- puts("parent stderr: " + data);
+ console.log("parent stderr: " + data);
});
child.stdout.setEncoding('utf8');
child.stdout.addListener("data", function (data){
- puts('child said: ' + JSON.stringify(data));
+ console.log('child said: ' + JSON.stringify(data));
if (!gotHelloWorld) {
assert.equal("hello world\r\n", data);
gotHelloWorld = true;
});
child.stdout.addListener("end", function (data){
- puts('child end');
+ console.log('child end');
});
cat.stdout.setEncoding('utf8');
cat.stdout.addListener("data", function (chunk) {
- puts("stdout: " + chunk);
+ console.log("stdout: " + chunk);
response += chunk;
});
cat.addListener("exit", function (status) {
- puts("exit event");
+ console.log("exit event");
exitStatus = status;
assert.equal("hello world", response);
});
child.stderr.setEncoding('utf8');
child.stderr.addListener("data", function (data) {
- puts("parent stderr: " + data);
+ console.log("parent stderr: " + data);
assert.ok(false);
});
child.stderr.setEncoding('utf8');
child.stdout.addListener("data", function (data) {
count += data.length;
- puts(count);
+ console.log(count);
});
child.addListener("exit", function (data) {
assert.equal(n, count);
- puts("okay");
+ console.log("okay");
});
try {
var crypto = require('crypto');
} catch (e) {
- puts("Not compiled with OPENSSL support.");
+ console.log("Not compiled with OPENSSL support.");
process.exit();
}
var sent_final_ping = false;
var server = dgram.createSocket(function (msg, rinfo) {
- puts("connection: " + rinfo.address + ":"+ rinfo.port);
+ console.log("connection: " + rinfo.address + ":"+ rinfo.port);
- puts("server got: " + msg);
+ console.log("server got: " + msg);
if (/PING/.exec(msg)) {
var buf = new Buffer(4);
server.bind(port, host);
server.addListener("listening", function () {
- puts("server listening on " + port + " " + host);
+ console.log("server listening on " + port + " " + host);
var buf = new Buffer(4);
buf.write('PING');
var client = dgram.createSocket();
client.addListener("message", function (msg, rinfo) {
- puts("client got: " + msg);
+ console.log("client got: " + msg);
assert.equal("PONG", msg.toString('ascii'));
count += 1;
});
client.addListener("close", function () {
- puts('client.close');
+ console.log('client.close');
assert.equal(N, count);
tests_run += 1;
server.close();
process.addListener("exit", function () {
assert.equal(4, tests_run);
- puts('done');
+ console.log('done');
});
var fs = require('fs');
function tryToKillEventLoop() {
- puts('trying to kill event loop ...');
+ console.log('trying to kill event loop ...');
fs.stat(__filename, function (err) {
if (err) {
throw new Exception('first fs.stat failed')
} else {
- puts('first fs.stat succeeded ...');
+ console.log('first fs.stat succeeded ...');
fs.stat(__filename, function (err) {
if (err) {
throw new Exception('second fs.stat failed')
} else {
- puts('second fs.stat succeeded ...');
- puts('could not kill event loop, retrying...');
+ console.log('second fs.stat succeeded ...');
+ console.log('could not kill event loop, retrying...');
setTimeout(function () {
if (--count) {
if (err) throw err;
if (chunk) {
pos += bytesRead;
- //puts(pos);
+ //console.log(pos);
readChunk();
} else {
fs.closeSync(fd);
// require() calls..
N = 30;
for (var i=0; i < N; i++) {
- puts("start " + i);
+ console.log("start " + i);
fs.readFile(testTxt, function(err, data) {
if (err) {
- puts("error! " + e);
+ console.log("error! " + e);
process.exit(1);
} else {
- puts("finish");
+ console.log("finish");
}
});
}
fs.stat("does-not-exist-" + i, function (err) {
if (err) {
j++; // only makes it to about 17
- puts("finish " + j);
+ console.log("finish " + j);
} else {
throw new Error("this shouldn't be called");
}
// Count the tests
exits++;
- puts('.');
+ console.log('.');
});
}
var times_hello_emited = 0;
e.addListener("newListener", function (event, listener) {
- puts("newListener: " + event);
+ console.log("newListener: " + event);
events_new_listener_emited.push(event);
});
e.addListener("hello", function (a, b) {
- puts("hello");
+ console.log("hello");
times_hello_emited += 1
assert.equal("a", a);
assert.equal("b", b);
});
-puts("start");
+console.log("start");
e.emit("hello", "a", "b");
count = 0;
function listener1 () {
- puts('listener1');
+ console.log('listener1');
count++;
}
function listener2 () {
- puts('listener2');
+ console.log('listener2');
count++;
}
function listener3 () {
- puts('listener3');
+ console.log('listener3');
count++;
}
var caughtException = false;
process.addListener('uncaughtException', function (e) {
- puts("uncaught exception! 1");
+ console.log("uncaught exception! 1");
assert.equal(MESSAGE, e.message);
caughtException = true;
});
process.addListener('uncaughtException', function (e) {
- puts("uncaught exception! 2");
+ console.log("uncaught exception! 2");
assert.equal(MESSAGE, e.message);
caughtException = true;
});
}, 10);
process.addListener("exit", function () {
- puts("exit");
+ console.log("exit");
assert.equal(true, caughtException);
});
exec("ls /", function (err, stdout, stderr) {
if (err) {
error_count++;
- puts("error!: " + err.code);
- puts("stdout: " + JSON.stringify(stdout));
- puts("stderr: " + JSON.stringify(stderr));
+ console.log("error!: " + err.code);
+ console.log("stdout: " + JSON.stringify(stdout));
+ console.log("stderr: " + JSON.stringify(stderr));
assert.equal(false, err.killed);
} else {
success_count++;
assert.equal(true, err.code != 0);
assert.equal(false, err.killed);
assert.strictEqual(null, err.signal);
- puts("error code: " + err.code);
- puts("stdout: " + JSON.stringify(stdout));
- puts("stderr: " + JSON.stringify(stderr));
+ console.log("error code: " + err.code);
+ console.log("stdout: " + JSON.stringify(stdout));
+ console.log("stderr: " + JSON.stringify(stderr));
} else {
success_count++;
p(stdout);
isDebug ? 'node_g' : 'node');
nodePath = path.normalize(nodePath);
-puts('nodePath: ' + nodePath);
-puts('process.execPath: ' + process.execPath);
+console.log('nodePath: ' + nodePath);
+console.log('process.execPath: ' + process.execPath);
assert.equal(nodePath, process.execPath);
});
process.addListener("exit", function () {
- puts("done");
+ console.log("done");
assert.equal(true, got_error);
});
if (err) {
got_error = true;
} else {
- puts(fs.statSync(file).mode);
+ console.log(fs.statSync(file).mode);
assert.equal(0777, fs.statSync(file).mode & 0777);
fs.chmodSync(file, 0644);
process.addListener('exit', function() {
assert.equal(readCalled, 1);
-});
\ No newline at end of file
+});
process.addListener('exit', function() {
assert.equal(readCalled, 1);
-});
\ No newline at end of file
+});
fs.readFile(fn, function(err, data) {
assert.ok(data);
-});
\ No newline at end of file
+});
function runNextTest(err) {
if (err) throw err;
var test = tests.shift()
- if (!test) puts(numtests+' subtests completed OK for fs.realpath');
+ if (!test) console.log(numtests+' subtests completed OK for fs.realpath');
else test(runNextTest);
}
runNextTest();
fs.close(fd);
});
-puts("stating: " + __filename);
+console.log("stating: " + __filename);
fs.stat(__filename, function (err, s) {
if (err) {
got_error = true;
p(s);
success_count++;
- puts("isDirectory: " + JSON.stringify( s.isDirectory() ) );
+ console.log("isDirectory: " + JSON.stringify( s.isDirectory() ) );
assert.equal(false, s.isDirectory());
- puts("isFile: " + JSON.stringify( s.isFile() ) );
+ console.log("isFile: " + JSON.stringify( s.isFile() ) );
assert.equal(true, s.isFile());
- puts("isSocket: " + JSON.stringify( s.isSocket() ) );
+ console.log("isSocket: " + JSON.stringify( s.isSocket() ) );
assert.equal(false, s.isSocket());
- puts("isBlockDevice: " + JSON.stringify( s.isBlockDevice() ) );
+ console.log("isBlockDevice: " + JSON.stringify( s.isBlockDevice() ) );
assert.equal(false, s.isBlockDevice());
- puts("isCharacterDevice: " + JSON.stringify( s.isCharacterDevice() ) );
+ console.log("isCharacterDevice: " + JSON.stringify( s.isCharacterDevice() ) );
assert.equal(false, s.isCharacterDevice());
- puts("isFIFO: " + JSON.stringify( s.isFIFO() ) );
+ console.log("isFIFO: " + JSON.stringify( s.isFIFO() ) );
assert.equal(false, s.isFIFO());
- puts("isSymbolicLink: " + JSON.stringify( s.isSymbolicLink() ) );
+ console.log("isSymbolicLink: " + JSON.stringify( s.isSymbolicLink() ) );
assert.equal(false, s.isSymbolicLink());
assert.ok(s.mtime instanceof Date);
try {fs.unlinkSync(linkPath);}catch(e){}
fs.symlink(linkData, linkPath, function(err){
if (err) throw err;
- puts('symlink done');
+ console.log('symlink done');
// todo: fs.lstat?
fs.readlink(linkPath, function(err, destination) {
if (err) throw err;
try {fs.unlinkSync(dstPath);}catch(e){}
fs.link(srcPath, dstPath, function(err){
if (err) throw err;
- puts('hard link done');
+ console.log('hard link done');
var srcContent = fs.readFileSync(srcPath, 'utf8');
var dstContent = fs.readFileSync(dstPath, 'utf8');
assert.equal(srcContent, dstContent);
fs.open(fn, 'w', 0644, function (err, fd) {
if (err) throw err;
- puts('open done');
+ console.log('open done');
fs.write(fd, expected, 0, "utf8", function (err, written) {
- puts('write done');
+ console.log('write done');
if (err) throw err;
assert.equal(Buffer.byteLength(expected), written);
fs.closeSync(fd);
found = fs.readFileSync(fn, 'utf8');
- puts('expected: ' + expected.toJSON());
- puts('found: ' + found.toJSON());
+ console.log('expected: ' + expected.toJSON());
+ console.log('found: ' + found.toJSON());
fs.unlinkSync(fn);
});
});
});
c.addListener("data", function (chunk) {
- puts(chunk);
+ console.log(chunk);
server_response += chunk;
});
});
});
-sys.puts('Server running at http://127.0.0.1:'+PORT+'/')
+console.log('Server running at http://127.0.0.1:'+PORT+'/')
var body = "exports.A = function() { return 'A';}";
var server = http.createServer(function (req, res) {
- puts("got request");
+ console.log("got request");
res.writeHead(200, [
["Content-Length", body.length],
["Content-Type", "text/plain"]
if (err) {
throw err;
} else {
- puts("got response");
+ console.log("got response");
got_good_server_content = true;
assert.equal(body, content);
server.close();
http.cat("http://localhost:12312/", "utf8", function (err, content) {
if (err) {
- puts("got error (this should happen)");
+ console.log("got error (this should happen)");
bad_server_got_error = true;
}
});
});
process.addListener("exit", function () {
- puts("exit");
+ console.log("exit");
assert.equal(true, got_good_server_content);
assert.equal(true, bad_server_got_error);
});
http.cat("http://127.0.0.1:"+PORT+"/", "utf8", function (err, data) {
if (err) throw err;
assert.equal('string', typeof data);
- puts('here is the response:');
+ console.log('here is the response:');
assert.equal(UTF8_STRING, data);
- puts(data);
+ console.log(data);
server.close();
})
req.setBodyEncoding("utf8");
req.addListener('data', function (chunk) {
- puts("server got: " + JSON.stringify(chunk));
+ console.log("server got: " + JSON.stringify(chunk));
sent_body += chunk;
});
req.addListener('end', function () {
server_req_complete = true;
- puts("request complete from server");
+ console.log("request complete from server");
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('hello\n');
res.end();
req.addListener('response', function(res) {
res.setEncoding("utf8");
res.addListener('data', function(chunk) {
- puts(chunk);
+ console.log(chunk);
});
res.addListener('end', function() {
client_res_complete = true;
}
});
if (done_reqs === 4) {
- sys.puts("Got all requests, which is bad.");
+ console.log("Got all requests, which is bad.");
clearTimeout(timer);
}
}
});
function exception_handler(err) {
- sys.puts("Caught an exception: " + err);
+ console.log("Caught an exception: " + err);
if (err.name === "AssertionError") {
throw(err);
}
var command = "ab " + opts + " http://127.0.0.1:" + PORT + "/";
exec(command, function (err, stdout, stderr) {
if (err) {
- puts("ab not installed? skipping test.\n" + stderr);
+ console.log("ab not installed? skipping test.\n" + stderr);
process.exit();
return;
}
server.listen(PORT, function () {
runAb("-c 1 -n 10", function () {
- puts("-c 1 -n 10 okay");
+ console.log("-c 1 -n 10 okay");
runAb("-c 1 -n 100", function () {
- puts("-c 1 -n 100 okay");
+ console.log("-c 1 -n 100 okay");
runAb("-c 1 -n 1000", function () {
- puts("-c 1 -n 1000 okay");
+ console.log("-c 1 -n 1000 okay");
server.close();
});
});
nrequests_expected = 1;
var s = http.createServer(function (req, res) {
- puts("req: " + JSON.stringify(url.parse(req.url)));
+ console.log("req: " + JSON.stringify(url.parse(req.url)));
res.writeHead(200, {"Content-Type": "text/plain"});
res.write("Hello World");
var callbacks = 0;
parser.onMessageBegin = function () {
- puts("message begin");
+ console.log("message begin");
callbacks++;
};
parser.onHeadersComplete = function (info) {
- puts("headers complete: " + JSON.stringify(info));
+ console.log("headers complete: " + JSON.stringify(info));
assert.equal('GET', info.method);
assert.equal(1, info.versionMajor);
assert.equal(1, info.versionMinor);
};
parser.onPath = function (b, off, length) {
- puts("path [" + off + ", " + length + "]");
+ console.log("path [" + off + ", " + length + "]");
var path = b.asciiSlice(off, off+length);
- puts("path = '" + path + "'");
+ console.log("path = '" + path + "'");
assert.equal('/hello', path);
callbacks++;
};
http = require('http');
server = http.createServer(function (req, res) {
- sys.puts('got request. setting 1 second timeout');
+ console.log('got request. setting 1 second timeout');
req.connection.setTimeout(500);
req.connection.addListener('timeout', function(){
});
server.listen(PORT, function () {
- sys.puts('Server running at http://127.0.0.1:'+PORT+'/');
+ console.log('Server running at http://127.0.0.1:'+PORT+'/');
errorTimer =setTimeout(function () {
throw new Error('Timeout was not sucessful');
http.cat('http://localhost:'+PORT+'/', 'utf8', function (err, content) {
clearTimeout(errorTimer);
- sys.puts('HTTP REQUEST COMPLETE (this is good)');
+ console.log('HTTP REQUEST COMPLETE (this is good)');
});
});
have_openssl=true;
} catch (e) {
have_openssl=false;
- puts("Not compiled with OPENSSL support.");
+ console.log("Not compiled with OPENSSL support.");
process.exit();
}
if (req.id == 3) {
assert.equal("bar", req.headers['x-x']);
this.close();
- //puts("server closed");
+ //console.log("server closed");
}
setTimeout(function () {
res.writeHead(200, {"Content-Type": "text/plain"});
});
c.addListener("data", function (chunk) {
- puts(chunk);
+ console.log(chunk);
server_response += chunk;
});
c.addListener("end", function () {
client_got_eof = true;
- puts('got end');
+ console.log('got end');
c.end();
});
c.addListener("close", function () {
connection_was_closed = true;
- puts('got close');
+ console.log('got close');
server.close();
});
assert = require('assert');
server = http.createServer(function (request, response) {
- sys.puts('responding to ' + request.url);
+ console.log('responding to ' + request.url);
response.writeHead(200, {'Content-Type': 'text/plain'});
response.write('1\n');
require("../common");
var r = process.memoryUsage();
-puts(inspect(r));
+console.log(inspect(r));
assert.equal(true, r["rss"] > 0);
assert.equal(true, r["vsize"] > 0);
fs.mkdir(d, 0666, function (err) {
if (err) {
- puts("mkdir error: " + err.message);
+ console.log("mkdir error: " + err.message);
mkdir_error = true;
} else {
- puts("mkdir okay!");
+ console.log("mkdir okay!");
fs.rmdir(d, function (err) {
if (err) {
- puts("rmdir error: " + err.message);
+ console.log("rmdir error: " + err.message);
rmdir_error = true;
} else {
- puts("rmdir okay!");
+ console.log("rmdir okay!");
}
});
}
process.addListener("exit", function () {
assert.equal(false, mkdir_error);
assert.equal(false, rmdir_error);
- puts("exit");
+ console.log("exit");
});
assert.equal(true, errorThrownAsync);
- puts("exit");
+ console.log("exit");
});
});
process.addListener("exit", function () {
- puts("recv: " + JSON.stringify(recv));
+ console.log("recv: " + JSON.stringify(recv));
assert.equal(2*256, recv.length);
var a = recv.split("");
var first = a.slice(0,256).reverse().join("");
- puts("first: " + JSON.stringify(first));
+ console.log("first: " + JSON.stringify(first));
var second = a.slice(256,2*256).join("");
- puts("second: " + JSON.stringify(second));
+ console.log("second: " + JSON.stringify(second));
assert.equal(first, second);
});
var sent_final_ping = false;
var server = net.createServer(function (socket) {
- puts("connection: " + socket.remoteAddress);
+ console.log("connection: " + socket.remoteAddress);
assert.equal(server, socket.server);
socket.setNoDelay();
socket.setEncoding('utf8');
socket.addListener("data", function (data) {
- puts("server got: " + data);
+ console.log("server got: " + data);
assert.equal(true, socket.writable);
assert.equal(true, socket.readable);
assert.equal(true, count <= N);
});
socket.addListener("close", function () {
- puts('server socket.endd');
+ console.log('server socket.endd');
assert.equal(false, socket.writable);
assert.equal(false, socket.readable);
socket.server.close();
server.listen(port, host, function () {
- puts("server listening on " + port + " " + host);
+ console.log("server listening on " + port + " " + host);
var client = net.createConnection(port, host);
});
client.addListener("data", function (data) {
- puts("client got: " + data);
+ console.log("client got: " + data);
assert.equal("PONG", data);
count += 1;
});
client.addListener("close", function () {
- puts('client.endd');
+ console.log('client.endd');
assert.equal(N+1, count);
assert.equal(true, sent_final_ping);
tests_run += 1;
process.addListener("exit", function () {
assert.equal(4, tests_run);
- puts('done');
+ console.log('done');
});
});
socket.addListener("close", function (had_error) {
- //puts("server had_error: " + JSON.stringify(had_error));
+ //console.log("server had_error: " + JSON.stringify(had_error));
assert.equal(false, had_error);
});
});
server.listen(PORT, function () {
- puts('listening');
+ console.log('listening');
var client = net.createConnection(PORT);
client.setEncoding("UTF8");
client.addListener("connect", function () {
- puts("client connected.");
+ console.log("client connected.");
});
client.addListener("data", function (chunk) {
client_recv_count += 1;
- puts("client_recv_count " + client_recv_count);
+ console.log("client_recv_count " + client_recv_count);
assert.equal("hello\r\n", chunk);
client.end();
});
client.addListener("close", function (had_error) {
- puts("disconnect");
+ console.log("disconnect");
assert.equal(false, had_error);
if (disconnect_count++ < N)
client.connect(PORT); // reconnect
have_openssl=true;
} catch (e) {
have_openssl=false;
- puts("Not compiled with OPENSSL support.");
+ console.log("Not compiled with OPENSSL support.");
process.exit();
}
function get_printer(timeout) {
return function () {
- sys.puts("Running from setTimeout " + timeout);
+ console.log("Running from setTimeout " + timeout);
done.push(timeout);
};
}
process.nextTick(function () {
- sys.puts("Running from nextTick");
+ console.log("Running from nextTick");
done.push('nextTick');
})
setTimeout(get_printer(i), i);
}
-sys.puts("Running from main.");
+console.log("Running from main.");
process.addListener('exit', function () {
];
-puts('readdirSync ' + readdirDir);
+console.log('readdirSync ' + readdirDir);
var f = fs.readdirSync(readdirDir);
p(f);
assert.deepEqual(files, f.sort());
-puts("readdir " + readdirDir);
+console.log("readdir " + readdirDir);
fs.readdir(readdirDir, function (err, f) {
if (err) {
- puts("error");
+ console.log("error");
got_error = true;
} else {
p(f);
process.addListener("exit", function () {
assert.equal(false, got_error);
- puts("exit");
+ console.log("exit");
});
var sys = require('sys');
-//sys.puts('puts before');
+//console.log('puts before');
Object.prototype.xadsadsdasasdxx = function () {
};
-sys.puts('puts after');
+console.log('puts after');
require("../common");
-puts("process.pid: " + process.pid);
+console.log("process.pid: " + process.pid);
var first = 0,
second = 0;
process.addListener('SIGUSR1', function () {
- puts("Interrupted by SIGUSR1");
+ console.log("Interrupted by SIGUSR1");
first += 1;
});
process.addListener('SIGUSR1', function () {
second += 1;
setTimeout(function () {
- puts("End.");
+ console.log("End.");
process.exit(0);
}, 5);
});
i = 0;
setInterval(function () {
- puts("running process..." + ++i);
+ console.log("running process..." + ++i);
if (i == 5) {
process.kill(process.pid, "SIGUSR1");
});
setTimeout(function () {
- sys.puts("Sending SIGINT");
+ console.log("Sending SIGINT");
child.kill("SIGINT");
setTimeout(function () {
- sys.puts("Chance has been given to die");
+ console.log("Chance has been given to die");
done = true;
if (!childKilled) {
// Cleanup
- sys.puts("Child did not die on SIGINT, sending SIGTERM");
+ console.log("Child did not die on SIGINT, sending SIGTERM");
child.kill("SIGTERM");
}
}, 200);
+ "南越国是前203年至前111年存在于岭南地区的一个国家,国都位于番禺,疆域包括今天中国的广东、广西两省区的大部份地区,福建省、湖南、贵州、云南的一小部份地区和越南的北部。南越国是秦朝灭亡后,由南海郡尉赵佗于前203年起兵兼并桂林郡和象郡后建立。前196年和前179年,南越国曾先后两次名义上臣属于西汉,成为西汉的“外臣”。前112年,南越国末代君主赵建德与西汉发生战争,被汉武帝于前111年所灭。南越国共存在93年,历经五代君主。南越国是岭南地区的第一个有记载的政权国家,采用封建制和郡县制并存的制度,它的建立保证了秦末乱世岭南地区社会秩序的稳定,有效的改善了岭南地区落后的政治、##济现状。\n";
-puts(cmd + "\n\n");
+console.log(cmd + "\n\n");
try {
fs.unlinkSync(tmpFile);
fs.unlinkSync(tmpFile);
if (err) throw err;
- puts(stdout);
+ console.log(stdout);
assert.equal(stdout, "hello world\r\n" + string);
assert.equal("", stderr);
});
childProccess.exec(cmd, function(err) {
if (err) throw err;
- puts('done!');
+ console.log('done!');
var stat = fs.statSync(tmpFile);
- puts(tmpFile + ' has ' + stat.size + ' bytes');
+ console.log(tmpFile + ' has ' + stat.size + ' bytes');
assert.equal(size, stat.size);
fs.unlinkSync(tmpFile);
finished = false;
test(1024*1024, false, function () {
- puts("Done printing with string");
+ console.log("Done printing with string");
test(1024*1024, true, function () {
- puts("Done printing with buffer");
+ console.log("Done printing with buffer");
finished = true;
});
});
print(".");
}
}
-puts(" crayon!");
+console.log(" crayon!");
// üäö
-puts("Σὲ γνωρίζω ἀπὸ τὴν κόψη");
+console.log("Σὲ γνωρίζω ἀπὸ τὴν κόψη");
assert.equal(true, /Hellö Wörld/.test("Hellö Wörld") );