

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive set of questions and answers related to node.js, covering essential concepts such as streams, modules, asynchronous programming, and rest operations. It includes practical examples and explanations of key functions and patterns used in node.js development, making it a valuable resource for students and developers looking to deepen their understanding of node.js and its core functionalities. The content is structured to facilitate learning and review, with clear answers and concise explanations. It also covers npm commands and module usage, offering a practical guide to node.js development practices. Useful for exam preparation and quick reference.
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


.pipe() - ANSWER-a function that takes a readable source stream and outputs to a writable stream are for loops and async callbacks compatible? - ANSWER-not really, need to use recursion instead async.forEachSeries - ANSWER-iterates over every element in the provided array, calling the given function for each aync.auto function - ANSWER-lets you mix ordered and unordered functions together into one powerful sequence of functions can you chain multiple .pipe()'s together - ANSWER-yes console.assert(cond, message) - ANSWER-if cond evaluates to false, throw an AssertionFailure exception create a module that prints out "Hello World" - ANSWER-exports.hello_world = function () { console.log("Hello World"); } exports object - ANSWER-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 four core REST operations - ANSWER-get, put, post, delete fs.readdir(file, callback) - ANSWER-returns all items in the given folder except for "." and ".." GET /albums/italy2012.json - ANSWER-the request returns this album how do you handle a situation where you are losing the this pointer? - ANSWER- enclose the function within a function, then assign self to this (var self = this;). this preserves this via closures in function scope How to load script to Node REPL? - ANSWER-.load foo.js from within Node REPL If functions return immediately, why doesn't the node process exit immediately after the function has returned? - ANSWER-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
install sql with npm - ANSWER-npm install sql node's callback pattern - ANSWER-do_something(param1, param2, ..., paramN, function (err, results) { ... } ); npm install - ANSWER-installs the modules from package.json npm link - ANSWER-tells npm to put a link to the album-manager package in the local machine's default public package repo npm update - ANSWER-updates the modules from package.json parse this url: /albums/italy2012.json?page=1&page_size=20 - ANSWER- url.parse(req.url, true) //{ search: '?page=1&page_size=20', query: { page: '1', page_size: '20' }, pathname: '/albums/italy2012.json', path: '/albums/italy2012.json?page=1&page_size=20', href: '/albums/italy2012.json?page=1&page_size=20' } process.nextTick() - ANSWER-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 PUT /albums.json - ANSWER-The HTTP request body contains the JSON with the data for the new album. search for sql modules - ANSWER-npm search sql the async node module - ANSWER-provides an intuitive way to structure and organize asynchronous calls the pattern for using streams - ANSWER-.on(event_name, function (param) { ... }); update an installed package - ANSWER-npm update mysql (npm update to update all) what are streams - ANSWER-streams are a powerful way to transfer large amounts of data in Node while maintaining the asynchronous, nonblocking nature of the sytem what defines NodeJS - ANSWER-non-blocking IO and asynchronous programming what does the module variable of each module contain - ANSWER-information such as the filename of the current module, its child modules, its parent modules, etc