Math.pow HTMLElement window.document process.cwd RegExp fs.readFile console.log var http = require('http');
http.Server http.IncomingMessage http.ServerResponse http.ServerEvent EmitterEventEmitteron(event, handlerFunction)emit(event, data)Server objectmethodurlheadersServerResponseServer objectsetHeader(key, val)statusCodewrite(data[, encoding])node-core-apis/start/http-server-found.js
/foundHints:
Up Next: File System and Path Modules
var fs = require('fs');
fs.readfs.openfs.linkfs.writefs.chownfs.mkdirfs.statfs.readSyncfs.openSyncfs.linkSyncfs.writeSyncfs.chownSyncfs.mkdirSyncfs.statSyncfs.readFile(name[, options], cb)fs.writeFile(name, data[, options], cb)function myCallback(err, userRecord){
if(err) throw err;
else console.log(userRecord);
}
db.getUser({ id : 30 }, myCallback);
console.log('db query queued');
function gotUser(err, user){ ... }
function writeComplete(err){ ... }
function parseHTML(err, response){ ... }
db.getUser({ id : 1 }, gotUser);
fs.writeFile('message.txt', "JS is Gr8!", 'utf8', writeComplete);
http.get('http://sequoia.makes.software', parseHTML);
var myCallback = function(err, ...
Always!!
Back to Filesystem
readFile(name[, options], cb)writeFile(name, data[, options], cb)fs.writeFileletter.txt.console.error on errorconsole.log success on successHints
fs.writeFile)Extra Credit:
--apend, append instead of writeUp Next: Other Core Modules
path.join(part[, ...])path.resolve(part[, ...])path.basename(pathToFile)path.dirname(pathToFile)path.extname(pathToFile)url.parse(urlString)url.resolve(from,to)querystring.parse(queryStr)querystring.stringify(queryObject)process.cwd()process.envprocess.argvprocess.exit(code)node-core-apis/start/read-file-argv.js
node read-file.js someFile.txtcd .. and run it again)Hints:
console.log(process.argv);
CWD__dirname__filenamenode-core-apis/start/read-file-server.js
index.html on any requestHints
fs, http, & path modulesExtra Credit
Up Next: NPM & the Node Ecosystem