Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
4.3 kB
1
Indexable
Never
Here are some common Node.js interview questions:

    What is Node.js?

    Node.js is an open-source, cross-platform, runtime environment for executing JavaScript code outside of a browser.

    What is the difference between Node.js and JavaScript?

    JavaScript is a programming language. Node.js is a runtime environment for executing JavaScript code outside of a browser.

    What are the core modules of Node.js?

    Some core modules in Node.js are:
    HTTP: For HTTP server and client
    FS: For filesystem operations
    OS: For OS related functions
    Path: For path manipulating
    DNS: For DNS lookups
    Net: For TCP servers and clients

    What is NPM in Node.js?

    NPM is the package manager for Node.js packages. It stands for Node Package Manager.

    What is the purpose of package.json?

    The package.json file contains metadata for a Node.js project. It includes:
    Name and version of the package
    Dependencies (other packages it relies on)
    Scripts (useful scripts you can run)
    Author info, licenses, etc.

    What is callback in Node.js?

    A callback is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action.

    What is event loop in Node.js?

    The event loop is what allows Node.js to perform non-blocking I/O operations. It works by scheduling callback functions to execute when their events are triggered.

    What is the difference between synchronous and asynchronous functions?

    Synchronous functions block execution until the function completes, while asynchronous functions do not block execution.

    What is REPL in Node.js?

    REPL stands for Read Evaluate Print Loop. It's a Node.js environment that evaluates JavaScript expressions. Useful for testing snippets of JavaScript code.



Here are some advanced Node.js interview questions:

    What is the module.exports and exports in Node.js?

    module.exports exports an object or function as a module, exports is an alias for module.exports. Anything exported by exports can be imported by another module using require().

    What is the difference between process.nextTick() and setImmediate()?

    process.nextTick() defers the execution of a function to the next iteration of the event loop. setImmediate() executes the callback on a subsequent turn of the event loop. nextTick() has higher priority.

    What is the purpose of buffers in Node.js?

    Buffers are an array of bytes in Node.js used to handle binary data. They allow you to handle streams of binary data in Node.js.

    What is event emitter in Node.js?

    EventEmitters are objects that emit named events which trigger callback functions. Many built-in Node objects inherit from EventEmitter, including streams, HTTP requests, etc.
    You can also create your own EventEmitters by using the EventEmitter class.

    What is piping in Node.js?

    Piping is a mechanism where the output of one stream is fed as input into another stream. In Node.js, the | operator is used to pipe between streams. For example, you can pipe a file read stream into a file write stream to copy a file.

    What is the purpose of stream in Node.js?

    Streams are a way to handle reading/writing data in Node.js in a non-blocking manner. They are instances of the Stream class in the Node API.
    There are many types of streams - readable, writable, transform streams, etc.
    Streams are used extensively in Node.js for file I/O, HTTP requests/responses, process execution, etc.

    What is cluster module in Node.js?

    The cluster module allows you to easily spawn child processes that share server ports. It can be used to take advantage of multiple CPU cores and improve performance of a Node.js application.

    What is the difference between fork() and spawn()?

    Both fork() and spawn() are methods to spawn new processes in Node.js. The main differences are:

    fork() spawns child Node.js processes, while spawn() can spawn any executable.

    fork() has an extra communication channel between parent and child for sending messages.

    fork() child processes will have all the benefits of the Node.js thread pool and stdio transport.

    spawn() has no communication channel and a child process will have its own event loop.