Node.js
What is an easy way to trigger the code in a catch block to see whether it is working?
Add a throw call to the try block.
What will the following code print? try { throw 'error' } catch(e) { console.log(e) return } finally { console.log('finally') }
error finally
Which command can you use to check whether Node is installed with the expected version?
node -v
What characterizes a NoSQL database?
It consists of collections of any data.
In the code below, which saves an item to MongoDB, what does "Fruit" represent? var item = new Fruit(data) item.save((err) => {})
It is the model that specifies the collection and schema.
Which Node web framework offers an ORM subframework?
Sails
Which jQuery function can you use to execute when the document finishes loading?
$(() => {})
Which call implements an HTTP get request using jQuery?
$.get('http://mysite/page', (data)=> {})
Which statement is true regarding third-party command line interface packages?
They will be installed with the -g flag.
Which code should come instead of the ??? placeholder for this Jasmine test to pass? describe('calc', () => { it('should calculate 2 to the power of 3', () => { ??? }) })
expect(2**3).toBe(8)
Which line should be placed inside mymodule.js for the following code to print the number 8? var myModule = require('./my-module.js'); console.log(5 + mymodule.myvar);
exports.myvar=3;
Assuming data is a JSON object, how would you change the following call so it creates a proper JSON file? fs.writeFile('data.json', data)
fs.writeFile('data.json', JSON.stringify(data))
What makes Node attractive for developers?
Node uses the same language for frontend and backend.
What will the following code print? fs = require('fs'); function print(err,data) { console.log('point 1'); } console.log('point 2'); fs.readdir('c:/',print); console.log('point 3');
point 2 point 3 point 1
How can you write the following code in a different way? Assume this code is within an async function. Message.findOne({_id: "1234"}) .then( result => { console.log(result) })
result = await Message.findOne({_id: "1234"}) console.log(result)
Which statement is true regarding the two file-reading methods below? Method A: fs.readFile('./data.json', 'utf-8', function(err, data) {}) Method B: var data = require('./data.json')
string; object
The following code is an excerpt from an HTTP request handler. What will this code print to the console? message.save() .then(() => { return false }) .then(data => { console.log(data) })
the string "false"
What makes Socket.io different from a standard web server?
It offers bidirectional communication.
Will the following test (using mock code) work, and how should it be fixed if it does not? 1: it('should test something', (done) => { 2: some_async_func(result => { 3: expect(result).toEqual(expected_result) 4: }) 5: })
The test will always pass, unless you add "done()" after line 3.
Which code should come instead of the ??? placeholder to start the server-side Socket.io functionality? var app = express() var http = require('http').Server(app) var io = require('socket.io')(http) var server = ???(3000, () => { console.log('server is listening') })
http.listen