Math.pow
HTMLElement
window.document
process.cwd
RegExp
fs.readFile
console.log
var http = require('http');
http.Server
http.IncomingMessage
http.ServerResponse
http.Server
Event Emitter
EventEmitter
on(event, handlerFunction)
emit(event, data)
Server
objectmethod
url
headers
ServerResponse
Server
objectsetHeader(key, val)
statusCode
write(data[, encoding])
node-core-apis/start/http-server-found.js
/found
Hints:
Up Next: File System and Path Modules
var fs = require('fs');
fs.read
fs.open
fs.link
fs.write
fs.chown
fs.mkdir
fs.stat
fs.readSync
fs.openSync
fs.linkSync
fs.writeSync
fs.chownSync
fs.mkdirSync
fs.statSync
fs.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.writeFile
letter.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.env
process.argv
process.exit(code)
node-core-apis/start/read-file-argv.js
node read-file.js someFile.txt
cd ..
and run it again)Hints:
console.log(process.argv);
CWD
__dirname
__filename
node-core-apis/start/read-file-server.js
index.html
on any requestHints
fs
, http
, & path
modulesExtra Credit
Up Next: NPM & the Node Ecosystem