Top 50 Node.Js Interview Questions with Answers

Node.Js Interview Questions with Answers

1. What is Node.js?

a. A programming language
b. A web server
c. A runtime environment for JavaScript
d. A database management system

Answer: c

2. Which event loop does Node.js use?

a. Non-blocking
b. Blocking
c. Sequential
d. Parallel

Answer: a

3. What is the purpose of the Node.js modules?

a. To create reusable code
b. To import JavaScript libraries
c. To add new features to Node.js
d. To improve Node.js performance

Answer: a

4. What is callback hell?

a. When a function calls itself recursively
b. When too many callbacks are nested within one another
c. When a callback function returns an error
d. When a callback function takes too long to execute

Answer: b

5. What is the purpose of the Node.js package.json file?

a. To store metadata about the project
b. To store the project’s source code
c. To store the project’s dependencies
d. To store the project’s configuration settings

Answer: c

6. What is NPM?

a. Node Package Manager
b. Node Programming Module
c. Node Project Manager
d. Node Package Module

Answer: a

7. How can you install a Node.js module using NPM?

a. npm install module-name
b. node install module-name
c. module-name install npm
d. install npm module-name

Answer: a

8. What is a buffer in Node.js?

a. A temporary storage area for data
b. A data type used to represent binary data
c. A function used to read and write files
d. An object used to create streams

Answer: b

9. What is middleware in Node.js?

a. A function that is executed before processing a request
b. A function that is executed after processing a request
c. A function that is executed between two other functions
d. A function that is executed when an error occurs

Answer: c

10. What is the purpose of the Node.js http module?

a. To handle HTTP requests and responses
b. To create and manage web servers
c. To send emails
d. To connect to a database

Answer: a

11. Which HTTP method is used to update a resource?

a. GET
b. POST
c. PUT
d. DELETE

Answer: c

12. What is the difference between res.send() and res.end() methods in Node.js?

a. res.send() sends JSON data, while res.end() sends plain text
b. res.send() sends plain text, while res.end() sends JSON data
c. res.send() terminates the response, while res.end() does not
d. res.send() and res.end() are interchangeable

Answer: a

13. What is an EventEmitter in Node.js?

a. A function that listens for events
b. An object that emits events
c. A method that triggers an event
d. A module that handles events

Answer: b

14. What is the purpose of the fs module in Node.js?

a. To handle file system operations
b. To create and manage web servers
c. To send emails
d. To connect to a database

Answer: a

15. What is a route in Node.js?

a. A path to a file
b. A URL endpoint
c. A function that handles a specific HTTP request
d. A function that handles a specific HTTP response

Answer: b

16. What is Express.js?

a. A library for building web applications in Node.js
b. A Node.js module for handling HTTP requests and responses
c. An object-oriented programming language
d. A database management system

Answer: a

17. What is Mongoose?

a. A Node.js module for working with MongoDB
b. A Node.js module for working with MySQL
c. A web server framework for Node.js
d. A front-end framework for Node.js

Answer: a

18. What is the difference between MongoDB and MySQL?

a. MongoDB is a document-oriented database, while MySQL is a relational database
b. MongoDB is open source, while MySQL is not
c. MongoDB is faster than MySQL
d. MySQL is more scalable than MongoDB

Answer: a

19. What is the purpose of the cluster module in Node.js?

a. To create multiple child processes of a Node.js application
b. To create a cluster of web servers
c. To manage user sessions
d. To handle database connections

Answer: a

20. What is the purpose of the bcrypt module in Node.js?

a. To create and manage web servers
b. To encrypt and decrypt data
c. To handle file system operations
d. To connect to a database

Answer: b

21. What is the purpose of the Node.js net module?

a. To handle HTTP requests and responses
b. To handle TCP connections
c. To send emails
d. To connect to a database

Answer: b

22. What is the purpose of the forever module in Node.js?

a. To create and manage web servers
b. To continuously run a Node.js application
c. To handle file system operations
d. To connect to a database

Answer: b

23. What is the purpose of the Node.js child_process module?

a. To handle file system operations
b. To create and manage child processes
c. To handle HTTP requests and responses
d. To manage user sessions

Answer: b

24. What is a stream in Node.js?

a. A data type used to represent binary data
b. A buffer that is read or written to sequentially
c. A function that processes data asynchronously
d. An object that is used to create streams

Answer: b

25. What is the purpose of the Node.js util module?

a. To handle file system operations
b. To create and manage web servers
c. To provide utility functions
d. To connect to a database

Answer: c

26. What is a Readable stream in Node.js?

a. A stream that can only be read from
b. A stream that can only be written to
c. A stream that can be both read from and written to
d. A stream that is used to read and write files

Answer: a

27. What is a Writable stream in Node.js?

a. A stream that can only be read from
b. A stream that can only be written to
c. A stream that can be both read from and written to
d. A stream that is used to read and write files

Answer: b

28. What is the purpose of the os module in Node.js?

a. To handle file system operations
b. To create and manage web servers
c. To interact with the operating system
d. To connect to a database

Answer: c

29. What is the purpose of the http-proxy module in Node.js?

a. To handle HTTP requests and responses
b. To create and manage web servers
c. To proxy HTTP requests to other servers
d. To connect to a database

Answer: c

30. What is the purpose of the Node.js crypto module?

a. To handle file system operations
b. To create and manage web servers
c. To encrypt and decrypt data
d. To connect to a database

Answer: c

31. What is the purpose of the Node.js path module?

a. To provide utility functions for working with file paths
b. To create and manage web servers
c. To handle HTTP requests and responses
d. To connect to a database

Answer: a

32. What is the purpose of the Node.js url module?

a. To create and manage web servers
b. To handle HTTP requests and responses
c. To parse and format URLs
d. To connect to a database

Answer: c

33. What is the purpose of the Node.js zlib module?

a. To handle file system operations
b. To create and manage web servers
c. To compress and decompress data
d. To connect to a database

Answer: c

34. What is the purpose of the Node.js cluster module?

a. To create and manage child processes of a Node.js application
b. To create a cluster of web servers
c. To handle database connections
d. To handle user authentication and authorization

Answer: a

35. What is a Promise in Node.js?

a. A function that is executed before processing a request
b. An object that represents the eventual completion of an asynchronous operation
c. A method that triggers an event
d. A method that handles rejected Promises

Answer: b

36. What is the purpose of the Node.js assert module?

a. To handle HTTP requests and responses
b. To create and manage web servers
c. To write unit tests for Node.js applications
d. To connect to a database

Answer: c

37. What is the purpose of the Node.js debug module?

a. To create and manage web servers
b. To handle database connections
c. To improve the debugging capabilities of Node.js
d. To handle file system operations

Answer: c

38. What is the purpose of the Node.js dgram module?

a. To handle HTTP requests and responses
b. To handle datagram sockets
c. To create and manage web servers
d. To connect to a database

Answer: b

39. What is the purpose of the Node.js punycode module?

a. To encode and decode domain names
b. To create and manage web servers
c. To handle file system operations
d. To connect to a database

Answer: a

40. What is the purpose of the Node.js q module?

a. To create and manage web servers
b. To provide a simple and powerful promise-based API
c. To handle file system operations
d. To connect to a database

Answer: b

41. What is the purpose of the Node.js request module?

a. To handle HTTP requests and responses
b. To create and manage web servers
c. To handle file system operations
d. To connect to a database

Answer: a

42. What is the purpose of the Node.js sinon module?

a. To create and manage web servers
b. To improve the testing capabilities of Node.js
c. To handle file system operations
d. To connect to a database

Answer: b

43. What is a duplex stream in Node.js?

a. A stream that can only be read from
b. A stream that can only be written to
c. A stream that can be both read from and written to
d. A stream that is used to read and write files

Answer: c

44. What is the purpose of the Node.js tty module?

a. To handle HTTP requests and responses
b. To create and manage web servers
c. To interact with the terminal
d. To connect to a database

Answer: c

45. What is the purpose of the Node.js zlib-sync module?

a. To handle file system operations
b. To compress and decompress data synchronously
c. To handle HTTP requests and responses
d. To connect to a database

Answer: b

46. What is the purpose of the Node.js async module?

a. To provide a simple and powerful promise-based API
b. To handle file system operations
c. To create and manage web servers
d. To provide utility functions for working with asynchronous code

Answer: d

47. What is the purpose of the Node.js strong-agent module?

a. To create and manage web servers
b. To improve the performance of Node.js applications
c. To handle file system operations
d. To connect to a database

Answer: b

48. What is the purpose of the Node.js chokidar module?

a. To watch files and directories for changes
b. To create and manage web servers
c. To handle HTTP requests and responses
d. To connect to a database

Answer: a

49. What is the purpose of the Node.js fs-extra module?

a. To handle file system operations
b. To create and manage web servers
c. To handle HTTP requests and responses
d. To connect to a database

Answer: a

50. What is the purpose of the Node.js clusterize module?

a. To create and manage child processes of a Node.js application
b. To improve the scalability of a Node.js application
c. To handle database connections
d. To handle user authentication and authorization

Answer: b

Top 50 PHP Interview Questions with Answers

PHP Interview Questions with Answers

1. What does PHP stand for?

A. Personal Home Page
B. Preprocessor Hypertext
C. PHP Hypertext Processor
D. PHP Hyper Page

Answer: C

2. Which of the following is not a valid PHP variable name?

A. $my_var
B. $bar
C. $1var
D. $hey_hey

Answer: C

3. Which of the following is a PHP superglobal variable?

A. $GLOBALS
B. $my_var
C. $local
D. $x_variable

Answer: A

4. Which of the following functions is used to connect to a MySQL database?

A. mysql_connect()
B. php_connect()
C. connect_mysql()
D. mysqli_connect()

Answer: D

5. What is the difference between a GET and a POST method in PHP?

A. GET sends data as a URL parameter, while POST sends data behind the scenes.
B. POST sends data as a URL parameter, while GET sends data behind the scenes.
C. There is no difference.
D. GET and POST cannot be used in PHP.

Answer: A

6. Which of the following is true about PHP arrays?

A. Arrays must be declared with a specific size.
B. Arrays can only hold one data type.
C. Arrays are dynamic and can hold multiple data types.
D. Arrays can only be used with numeric indexes.

Answer: C

7. What is the difference between echo and print in PHP?

A. There is no difference.
B. print can only output strings, while echo can output anything.
C. echo can only output strings, while print can output anything.
D. echo and print are not used in PHP.

Answer: B

8. Which of the following is used to start a PHP session?

A. session_start()
B. session_begin()
C. start_session()
D. session()

Answer: A

9. Which of the following filter is used to validate an email address?

A. FILTER_VALIDATE_IP
B. FILTER_VALIDATE_URL
C. FILTER_VALIDATE_EMAIL
D. FILTER_VALIDATE_DATE

Answer: C

10. What is the function used to remove white spaces from the beginning and end of a string?

A. trim()
B. strip()
C. clean()
D. clear()

Answer: A

11. Which of the following is used to upload files in PHP?

A. upload_files()
B. upload()
C. move_uploaded_file()
D. file_upload()

Answer: C

12. Which of the following is not a PHP loop structure?

A. for loop
B. while loop
C. do-while loop
D. switch loop

Answer: D

13. Which of the following is used to insert data into a MySQL database?

A. mysqli_select()
B. mysqli_query()
C. mysqli_delete()
D. mysqli_insert()

Answer: B

14. Which of the following is used to include a file in PHP?

A. include()
B. require()
C. require_once()
D. All of the above

Answer: D

15. Which of the following is used to check if a file exists in PHP?

A. file_exist()
B. file_check()
C. file_exists()
D. file()

Answer: C

16. What is the difference between == and === operators in PHP?

A. There is no difference.
B. == is used for comparison, while === is used for assignment.
C. == is used for assignment, while === is used for comparison.
D. == compares both value and data type, while === compares only value.

Answer: D

17. Which of the following is used to return a random number in PHP?

A. rand()
B. random()
C. random_number()
D. number_rand()

Answer: A

18. Which of the following is used to create a function in PHP?

A. function_create()
B. function_make()
C. function()
D. create_function()

Answer: D

19. Which of the following can be used to add elements to the end of an array?

A. array_add()
B. array_push()
C. array_append()
D. array_insert()

Answer: B

20. Which of the following is used to redirect a user to another page in PHP?

A. header()
B. redirect()
C. go_to()
D. forward()

Answer: A

21. What is the scope of a variable in PHP?

A. The part of the program where the variable is accessible.
B. The part of the program where the variable is declared.
C. A variable has no scope.
D. A variable scope depends on its data type.

Answer: A

22. Which of the following is used to count the number of elements in an array in PHP?

A. count()
B. length()
C. size()
D. total()

Answer: A

23. Which of the following is used to convert a string to all uppercase letters in PHP?

A. to_upper()
B. uppercase()
C. strtoupper()
D. upcase()

Answer: C

24. What is a PHP constant?

A. A variable that can be changed.
B. A variable that cannot be changed.
C. A loop structure in PHP.
D. A conditional statement in PHP.

Answer: B

25. Which of the following is used to sort an array in alphabetical order in PHP?

A. sort()
B. sort_alphabetical()
C. asort()
D. rsort()

Answer: A

26. Which of the following is used to remove a specific element from an array in PHP?

A. array_remove()
B. array_delete()
C. unset()
D. remove()

Answer: C

27. Which of the following is used to read the contents of a file into a string in PHP?

A. file_string()
B. file_contents()
C. read_file()
D. file_get_contents()

Answer: D

28. Which of the following is used to check if a variable is empty in PHP?

A. empty()
B. is_empty()
C. isnull()
D. isempty()

Answer: A

29. Which of the following is used to round a number to the nearest whole number in PHP?

A. ceil()
B. floor()
C. round()
D. round_number()

Answer: C

30. How do you declare a multi-dimensional array in PHP?

A. $array[][] = value;
B. $array[][][];
C. $array[][];
D. $array[][] = value;

Answer: D

31. Which of the following is used to set the timezone in PHP?

A. timezone_set()
B. timezone()
C. date_default_timezone()
D. date_timezone_set()

Answer: C

32. Which of the following is used to convert a string to a date in PHP?

A. string_to_date()
B. date_create()
C. strtotime()
D. date()

Answer: C

33. Which of the following is used to open a file in PHP?

A. fopen()
B. open_file()
C. file_open()
D. file()

Answer: A

34. Which of the following is used to download a file in PHP?

A. download()
B. file_download()
C. header()
D. fopen()

Answer: C

35. What does the strlen() function do in PHP?

A. Calculates the size of a file.
B. Counts the number of lines in a file.
C. Calculates the length of a string.
D. Calculates the size of an array.

Answer: C

36. Which of the following is used to check if a variable is an array in PHP?

A. isarray()
B. is_array()
C. array_check()
D. check_array()

Answer: B

37. Which of the following is used to calculate the remainder of a division in PHP?

A. mod()
B. modulo()
C. division()
D. %

Answer: D

38. Which of the following is used to get the current date in PHP?

A. date()
B. time()
C. datetime()
D. getdate()

Answer: A

39. Which of the following is used to get the current time in PHP?

A. date()
B. time()
C. datetime()
D. gettime()

Answer: B

40. Which of the following is used to compare two strings in PHP?

A. strcompare()
B. strcmp()
C. compare()
D. string_compare()

Answer: B

41. Which of the following is used to check if a string contains another string in PHP?

A. str_contains()
B. strstr()
C. compare()
D. string_compare()

Answer: B

42. Which of the following is used to get the last character of a string in PHP?

A. end()
B. last_char()
C. last()
D. substr()

Answer: D

43. Which of the following is used to convert an array into a string in PHP?

A. implode()
B. array_to_string()
C. convert()
D. to_string()

Answer: A

44. Which of the following is used to generate a random string in PHP?

A. rand_string()
B. string_rand()
C. random_str()
D. str_rand()

Answer: D

45. Which of the following is used to remove duplicate values from an array in PHP?

A. unique()
B. array_unique()
C. remove_duplicates()
D. deduplicate()

Answer: B

46. What is the default maximum execution time for a PHP script?

A. 30 seconds
B. 60 seconds
C. 90 seconds
D. 120 seconds

Answer: B

47. Which of the following is used to convert a boolean value to a string in PHP?

A. str_boolean()
B. booltostr()
C. tostring()
D. strbool()

Answer: C

48. Which of the following is used to calculate the absolute value of a number in PHP?

A. abs()
B. absolute()
C. number_abs()
D. get_absolute()

Answer: A

49. What is the difference between require() and include() in PHP?

A. There is no difference.
B. include() returns a warning if the file is not found, while require() returns an error.
C. require() returns a warning if the file is not found, while include() returns an error.
D. require() and include() cannot be used in PHP.

Answer: B

50. What is a PHP namespace?

A. A container for functions and variables.
B. A way to organize code into logical groups.
C. A loop structure in PHP.
D. A conditional statement in PHP.

Answer: B

PHP OOP: Traits

What is Traits?

  • Code is shortened by using Traits.
  • One code is used everywhere just by writing the trait function.

Example :

Output:

Multi traits use example:

Output:

Tagged : / / / / / / / / / / / / / /

PHP OOP: Late Static Binding

Late static Binding:

  • Late static binding helps to override name by using static in echo keyword.
  • It helps lot for writing minimum coding.
  • The message of the base class is printed using the self keyword and the message of the derived class is printed using the static keyword.

Example to printing the message of base class:

Output:

Example of printing the message of derived class:

Output:

Tagged : / / / / / / / / / / / /

PHP OOP : Static Members

What is Static Members ?

  • Static properties and methods can be used without creating an instance of the class.
  • The static keyword is used to declare properties and methods of a class as static.
  • Object not create.
  • Stack keyword use before access modifier.
  • Inside class use self::(use static method).
  • inherit use parent class name ::(properties).

Example :

Example Constructor :-

Tagged : / / / / / / / / / / / / /

PHP OOP : Interfaces

What is Interfaces?

  • Interfaces help us to use multiple classes in a single class inherit.
  • Interfaces are declared with the interface keyword.
  • Derived class is called derived class.
  • object not be created in interface.
  • Property should not be defined in interface(class).
  • All interface methods must be public.
  • All methods in an interface are abstract.
  • To implement an interface, a class must use the implements keyword.

Example :-

Tagged : / / / / / / / / / / / / / /

PHP OOP : Abstract Classes

Abstract Class :

  • when we create abstract class then we can not create object of that abstract class.
  • If we want to use abstract class then we only access with derived class .
  • Just abstract write before the class name.
  • when we create abstract class two condition occurs one is abstract method like :- abstract protected function name ( );
  • abstract means incomplete method we declare but not implement (code).
  • In derived class we have to implement of that abstract method.
Tagged : / / / / / / / / / / / /

PHP OOP : Overriding properties and Methods

Overriding Properties :

  • Same properties on both classes (base and derived class).

Overriding Methods :

  • Same name of method on both classes base or derived class.
Tagged : / / / / / / / / / / / / /

PHP OOP : Access Modifier (public, protected, private)

What is the access modifier?

Restrictions on properties and methods.

Types of access modifier

  1. public
  2. protected
  3. private

Public :

  • Access on base as well as derived class and outside of the class.
  • Everyone can see and access the data.
  • Not secure.
  • Override use.

Protected :

  • Base and Derived class.
  • No one gets access throughout the class.
  • Declare like protected property and method.
  • Not use override function.
  • Without permission no one can access any of these (properties & method).

Private :

  • Access itself.
  • Highly secured.
  • No one can access without permission.
  • Highly costly.
Tagged : / / / / / / / / / / / / / / /

PHP OOP : Inheritance

What is inheritance in php?

  • Inheritance is properties of PHP.
  • Accessing the feature of one class of another class.
  • Three types that is single, multiple and multilevel inheritance.
  • It is the four pillars of oops.
  • It allows a class to reuse the code from another class without duplicating it.
  • Two classes one is base/main another one is derived class.
  • Base class only use its own function but in Derived class it use both function base or derived class.

How to use inheritance in php?

class school {
}
class students extends school {
}
$sch =new school (); // only use class school 
$stu = new students (); // use both class school students (properties and methods)

Example of main/base class use :-

Example of inheritance:

Tagged : / / / / / / / / / / / / / /