Node.js - how to get core module source
It is possible to ask node to show its core module source. For example, we want to check the source of the readFileSunc() method:
$ node
> fs = require('fs');
> fs.writeFileSync('fs.js', fs.toString())
> fs.writeFileSync('fs.readFileSync.js', fs.readFileSync.toString())
[Ctrl-C][Ctrl-C]
Now check the fs.readFileSync.js
file in the current folder.
Also on some systems source code of core node modules is in the /usr/lib/nodejs/
.
And another (less interesting) way to get core module source - is to look for it in the node github repository:
- check installed node.js version (node --version)
- find appropriate release on github (https://github.com/joyent/node/releases), for example 0.8.17
- click commit id on the left (like c50c33e)
- click "Browse code" and see the source
Node.js framework ships with workhorse connectors and libraries such as those relating to HTTP, SSL, compression, filesystem access, and raw TCP and UDP. JavaScript, already tuned for a Web browser's event loop environment for GUI and network events, is a great language for wiring up these connectors.
ReplyDelete