returns all items in the given folder except for "." and ".."
Back
create a module that prints out "Hello World"
Front
exports.hello_world = function () {
console.log("Hello World");
}
Back
what is the global object in NodeJS
Front
similar to window object for JS in the browser, anything attached to the global object is available anywhere in your node app
Back
can you chain multiple .pipe()'s together
Front
yes
Back
where does npm install module packages
Front
the node_mpdules subdirectory of your project
Back
four core REST operations
Front
get, put, post, delete
Back
what does the module variable of each module contain
Front
information such as the filename of the current module, its child modules, its parent modules, etc
Back
what defines NodeJS
Front
non-blocking IO and asynchronous programming
Back
what is the most powerful and awesome feature of the Node.js module system
Front
in a situation where you have a main widget and a special widget, each with their own node_modules/ dir, requiring special widget will import it's node_modules/, not the main widget's. version control.
Back
PUT /albums.json
Front
The HTTP request body contains the JSON with the data for the new album.
Back
are for loops and async callbacks compatible?
Front
not really, need to use recursion instead
Back
parse this url: /albums/italy2012.json?page=1&page_size=20
tells npm to put a link to the album-manager package in the local machine's default public package repo
Back
npm update
Front
updates the modules from package.json
Back
aync.auto function
Front
lets you mix ordered and unordered functions together into one powerful sequence of functions
Back
write a synchronous version of a script to read a file
Front
var fs = require('fs');
var handle = fs.openSync('info.txt', 'r');
var buf = new Buffer(100000);
var read = fs.readSync(handle, buf, 0, 10000, null);
console.log(buf.toString('utf-8', 0, read));
fs.closeSync(handle);
Back
how do you handle a situation where you are losing the this pointer?
Front
enclose the function within a function, then assign self to this (var self = this;). this preserves this via closures in function scope
Back
the async node module
Front
provides an intuitive way to structure and organize asynchronous calls
Back
install sql with npm
Front
npm install sql
Back
exports object
Front
a special object created by the Node module system in every file you create and is returned as the value of the require function when you include the module
Back
How to load script to Node REPL?
Front
.load foo.js from within Node REPL
Back
the pattern for using streams
Front
.on(event_name, function (param) { ... });
Back
console.assert(cond, message)
Front
if cond evaluates to false, throw an AssertionFailure exception
Back
If functions return immediately, why doesn't the node process exit immediately after the function has returned?
Front
Node operates on an event queue; if there are pending events awaiting a response, it doesn't exit until your code has finished executing AND there are no events left in the queue
Back
.pipe()
Front
a function that takes a readable source stream and outputs to a writable stream
Back
async.forEachSeries
Front
iterates over every element in the provided array, calling the given function for each
Back
write a function to asynchronously open and read a file
Front
fs.open( 'into.txt', 'r', function (err, handle) {
var buf = new Buffer(100000);
fs.read(
handle, buf, 0, 100000, null,
function (err, length) {
console.log(buf.toString('utf-8', 0, length));
fs.close(handle, function () { });
}
);
});
Back
what are streams
Front
streams are a powerful way to transfer large amounts of data in Node while maintaining the asynchronous, nonblocking nature of the sytem
Back
npm install
Front
installs the modules from package.json
Back
process.nextTick()
Front
defers the execution of an action till the next pass around the event loop, it is executed on a whole new stack. useful when preventing cpu intensive tasks from blocking other processes
Back
what is the require function
Front
a way to include additional functionality to node programs
var fs = require('fs'); // includes file system module
Back
GET /albums/italy2012.json
Front
the request returns this album
Back
update an installed package
Front
npm update mysql
(npm update to update all)
Back
write a function that handles errors in callbacks
Front
fs.open(
'info.txt', 'r',
function (err, handle) {
if (err) {
console.log("ERROR: " + err.code + " (" + err.message ")");
return;
} else {
// success! continue working here
}
);