Skip to main content

49 NodeJS Questions


  1. Difference between Javascript & NodeJS
    1. Javascript is a programming language
    2. NodeJS is a interpreter and environment for Javascript
    3. Javascript is used for any client-side activity for web development
    4. NodeJS is used to accessing or performing any non-blocking operation of any operating system
    5. Javascript runs in browsers
    6. NodeJS runs in V8 Engine
  2. What is NodeJS
    1. Open source
    2. Server Environment
    3. Javascript Framework
    4. Developed on Chrome's V8 Engine
    5. Free
    6. Compiles Javascript to Machine Code
    7. Used to create server-side web applications
    8. Apt for data intensive real-time applications
    9. Asynchronous Programming
    10. Can create dynamic page content
    11. Can do CRUD operations on files
    12. Can collect form data
    13. Can modify database
  3. Benefits of NodeJS
    1. Open sources
    2. Simple and Fast
    3. Asynchronous I/O
    4. Highly scalable
    5. Single Threaded
    6. Uses V8 Engine to convert Javascript to machine code
    7. Cross Platform - Runs on Windows, Linux, Unix, MacOS, etc
  4. Difference between Angular & NodeJS
    1. Angular
      1. is open source
      2. web application development framework 
      3. written in typescript
      4. used to build single page applications
      5. is a framework
      6. ideal for creating interactive web applications
      7. based on MVC model
      8. suitable for developing realtime applications
    2. NodeJS
      1. is open source
      2. cross platform runtime environment for applications
      3. written is C, C++, and javascript
      4. used to build server side networking applications
      5. has many frameworks run using it
      6. ideal for developing small sized projects
      7. helpful in generating Database queries
      8. suitable in situations where something fast and more scalable is required
  5. Why NodeJS is single threaded?
    1. to support asynchronous programming
    2. more scalable under web loads
    3. non-blocking
  6. How does NodeJS work?
    1. NodeJS is a virtual machine
    2. Uses Javascript as its scripting language
    3. Runs on V8 Engine (Environment)
    4. NOT a web server
    5. Does not have config file to point to HTML files
    6. To make it work like HTTP server, you have to write an HTTP server by using its built-in library
    7. Works on single-threaded event loop and a non-blocking I/O, provides high speed as it can handle high number of concurrent requests simultaneously.
    8. By using HTTP module, NodeJS can run on any web server
    9. NodeJS is a Javascript Runtime/Environment built on Chrome's V8 Javascript Engine
  7. Where can NodeJS be used?
    1. Real-time web applications
    2. Network applications
    3. General purpose applications
  8. How many API functions are there in NodeJS?
    1. Asynchronous functions - non-blocking functions
    2. Synchronous functions - blocking functions
  9. Difference between Async and Sync functions?
    1. Async is when its done parallelly
    2. Sync is when a function is completed as soon as it is called
  10. What is Package.json?
    1. Introduction to any NodeJS project
    2. It is the manifest file which holds the metadata of the project, where we define the properties of the project
    3. It holds info like
      1. Author
      2. Name
      3. Description
      4. Version
      5. Scripts
      6. Engines
      7. Dependencies
      8. Dev-dependencies
  11. What is event-driven programming?
    1. Programming approach that uses events
    2. Reason for NodeJS being fast
    3. It follows publish and subscribe pattern
  12. What is an event loop?
    1. allows non-blocking I/O operations
    2. handles all callbacks asynchronously
    3. follows publish and subscribe pattern
    4. event emitters emit events
    5. event handlers handle events
    6. all all events go into a loop, called as event loop
  13. What is REPL?
    1. Read
    2. Evaluate
    3. Print
    4. Loop
    5. REPL also known as Node Shell
  14. Lists tasks to be done asynchronously using NodeJS
    1. I/O operations
    2. Heavy computations
    3. Blocking operations
  15. List steps of Control Flow controls function calls in NodeJS?
    1. Control order of execution
    2. Gather data
    3. Limit Concurrency
    4. Invoke Next Steps
  16. What is a test pyramid?
    1. Unit Test
    2. Integration Test
    3. End to End Test
  17. What is error first callback?
    1. first argument of a callback is reserved for errors
    2. second argument of a callback is reserved for success data
  18. Purpose of module.exports
    1. Output of a module is saved into module.exports
  19. What is reactor pattern in NodeJS?
    1. Idea of Non-blocking I/O operations in NodeJS
    2. Provides a handler (callback function) associated with each I/O operation
    3. As soon as I/O operation request is generated, it is submitted to demultiplexer
    4. Demultiplexer is a notification interface which is capable of handling concurrency in non-blocking I/O mode
    5. Helps in collecting each request as event and placing them in a queue
    6. Resulting in generation of a even queue
  20. What si the difference between frontend and backend development?
    1. Frontend involves client-side coding
    2. Backend involves server-side coding
  21. What is LTS?
    1. Long Term Support (LTS) - stable realease by NodeJS that has support upto 18 months
  22. List major security implementations
    1. Authentication
    2. Error Handling
  23. What is callback hell?
    1. Pyramid of doom
    2. callback inside callback inside callback multiple times making room for errors
  24. Explain libuv
    1. library for nodejs
    2. used for asynchronous I/O
    3. efficient event loop
  25. What is a middleware?
    1. Function that receives request and response objects
    2. has access to request object, response object
    3. helps in finishing request response cycle
    4. next middleware function helps move to next middleware
  26. What is a URL module?
    1. helps read various parts of a url
  27. What is ESLint?
    1. used for linting javascript
  28. Why V8 Engine for NodeJS?
    1. it is fast
  29. Control Flow working?
    1. to control order of execution
  30. Two arguments that async.queue takes as input
    1. task function
    2. concurrency value
  31. spawn() and fork() methods
    1. spawn() is used to launch new process
    2. fork() is special instance of spawn() that executes new instance of V8 engine
    3. fork() is subset of spawn()
  32. Global objects
    1. available in all modules of application
    2. use env.process
  33. Stub in nodejs
    1. small functions used to stimulate behaviour of module or component
    2. during test cases, stubs provide answers to the functions
  34. Assert
    1. used to write test
    2. provides feedback when testcase fails
  35. Test Pyramid
    1. Mike Cohn developed the concept
    2. More unit tests than integration tests and more integration tests than end to end tests
  36. ExpressJS
    1. framework to manage flow of data between server and routes in the server-side applications
    2. Lightweight and flexible framework
    3. Developed on Middleware module called connect
  37. process.nextTick() and setImmediate()
    1. process.nextTick() does not queues its csllbacks on the event loop but setImmediate() queues
  38. Buffer class
    1. global class available everywhere
    2. stores raw data
    3. pure javascript is not compatible with binary data and so buffer
  39. node.js handles child threads
    1. nodejs is single threaded process
    2. does not show how it manages threads
    3. if you still want to use then include module childProcess explicitly
  40. What is stream?
    1. collection of data like arrays and strings
    2. read or write in a continuous manner
    3. used to process large set of data
  41. Use of NODE_ENV?
    1. if project in production or development environment is checked by looking at the value of NODE_ENV
  42. readFile and createReadStream?
    1. readFile is completely buffered
    2. createReadStream is not completely buffered. divided into chuncks of data and passed
    3. readFile is memory intensive process but not createReadStream
  43. Time
    1. setTimeout/clearTimeout
    2. setInterval/clearInterval
    3. setImmediate/clearImmediate
    4. process.nextTick
  44. Punnycode
    1. convert UTF-8 to ASCII
  45. NodeJS, AJAX
    1. NodeJS serverside
    2. AJAX client side
  46. Debugger?
    1. there is one built in
  47. event emitter
    1. nodejs class that emits events
  48. Cryptogrpahy
    1. using crypto module
  49. Express app and server must be set separate
    1. faster testing of APIs without using network
    2. cleaner code

Comments

Popular posts from this blog

Python - List - Append, Count, Extend, Index, Insert, Pop, Remove, Reverse, Sort

🐍 Advance List List is widely used and it's functionalities are heavily useful. Append Adds one element at the end of the list. Syntax list1.append(value) Input l1 = [1, 2, 3] l1.append(4) l1 Output [1, 2, 3, 4] append can be used to add any datatype in a list. It can even add list inside list. Caution: Append does not return anything. It just appends the list. Count .count(value) counts the number of occurrences of an element in the list. Syntax list1.count(value) Input l1 = [1, 2, 3, 4, 3] l1.count(3) Output 2 It returns 0 if the value is not found in the list. Extend .count(value) counts the number of occurrences of an element in the list. Syntax list1.extend(list) Input l1 = [1, 2, 3] l1.extend([4, 5]) Output [1, 2, 3, 4, 5] If we use append, entire list will be added to the first list like one element. Extend, i nstead of considering a list as one element, it joins the two lists one after other. Append works in the following way. Input l1 = [1, 2, 3] l1.append([4, 5]) Output...

Difference between .exec() and .execPopulate() in Mongoose?

Here I answer what is the difference between .exec() and .execPopulate() in Mongoose? .exec() is used with a query while .execPopulate() is used with a document Syntax for .exec() is as follows: Model.query() . populate ( 'field' ) . exec () // returns promise . then ( function ( document ) { console . log ( document ); }); Syntax for .execPopulate() is as follows: fetchedDocument . populate ( 'field' ) . execPopulate () // returns promise . then ( function ( document ) { console . log ( document ); }); When working with individual document use .execPopulate(), for model query use .exec(). Both returns a promise. One can do without .exec() or .execPopulate() but then has to pass a callback in populate.

683 K Empty Slots

  Approach #1: Insert Into Sorted Structure [Accepted] Intuition Let's add flowers in the order they bloom. When each flower blooms, we check it's neighbors to see if they can satisfy the condition with the current flower. Algorithm We'll maintain  active , a sorted data structure containing every flower that has currently bloomed. When we add a flower to  active , we should check it's lower and higher neighbors. If some neighbor satisfies the condition, we know the condition occurred first on this day. Complexity Analysis Time Complexity (Java):  O(N \log N) O ( N lo g N ) , where  N N  is the length of  flowers . Every insertion and search is  O(\log N) O ( lo g N ) . Time Complexity (Python):  O(N^2) O ( N 2 ) . As above, except  list.insert  is  O(N) O ( N ) . Space Complexity:  O(N) O ( N ) , the size of  active . Approach #2: Min Queue [Accepted] Intuition For each contiguous block ("window") of  k  po...