Node.js Interview Questions and answers

1. Explain error-first callback?
Answer : Error-first callbacks are used to pass errors and data. The first argument is always an error object that the programmer has to check if something went wrong. Additional arguments are used to pass data.

2. Explain how can you avoid callback hells?
Answer : modularization: break callbacks into independent functions
use a control flow library, like async
use generators with Promises
use async/await

3. Explain Promises?
Answer : Promises are a concurrency primitive, first described in the 80s. Now they are part of most modern programming languages to make your life easier. Promises can help you better handle async operations.

4. How can you listen on port 80 with Node?
Answer :Run the application on any port above 1024, and then put a reverse proxy like nginx in front of it.

5. What are the tools can be used to assure consistent style?
Answer :

6. Explain the difference between operational and programmer errors?
Answer : Operation errors are not bugs, but problems with the system, like request timeout or hardware failure.
On the other hand programmer errors are actual bugs.

7. What is a stub?
Answer : Stubs are functions/programs that simulate the behaviours of components/modules. Stubs provide canned answers to function calls made during test cases. Also, you can assert on with what these stubs were called.

8. What is a test pyramid?
Answer : A test pyramid describes that when writings test cases there should be a lot more low-level unit tests than high level end-to-end tests.

9. What is node.js?
Answer : Node.js is a Server side scripting which is used to build scalable programs. Its multiple advantages over other server side languages, the prominent being non-blocking I/O.

10. What tools can be used to assure consistent style?
Answer :

Comments are closed here.