Quick Contact


    Q21-: How assert works in Node.js?

    Assert mainly used to write test, it only provides feedback when running test cases fails. Whenever testing is done wherever talk about pyramid of testing includes unit test, integration test and end to end test.

    It is basically used by Node.js internally but using requires (“assert”) code, it can be used in other applications as well.

    		Var assert = require (‘assert’);
    		Function nul(a, b) {
    		Return a = b;
    		}
    		Var result = nul (1,2);
    		Assert (result === 2, ‘one multiplied by two is two’);
    	
    Q22-: Concept of test pyramid. Explain the process to implement them in terms of HTTP APIs.

    Test pyramid concept developed by Mike Cohn. It says that you have large number of unit tests (low-level) as compared to end-to-end tests (high-level) that running through GUI, which means whenever you are doing testing of any node project you should have more number of unit test because unit tests are specific to small multiple modules.

    In terms of HTTP APIs defined as-:

    1. Large number of unit tests (low-level) for every module.
    2. It says to test model interactions there should be lesser integration tests.
    3. For testing actual HTTP endpoints acceptance tests should be less.
    Q23-: What is purpose of Express.js package?

    Express.js facilitates the management of data flow between routes and server in server-side application. It is top built framework of Node.js. It is lightweight and flexible framework that provides various features for web application. It is developed on middleware module of node.js called connect. If you are working with connect based middleware modules, and then you can easily integrate with Express.js.

    Q24-: What do you understand by event emitter in Node.js?

    Event Emitter is a class off Node.js that capable of emitting the events and how you wrote the events in Node.js program as below-:

    There is parent class and custom class and emitting the event “myEmitter” as-:

    		Const EventEmitter = require (‘events’);
    		Class MyEmitter extends EventEmitter {}
    		Const myEmitter = new My Emitter();
    		myEmitter.on(‘event’, () => {
    		console.log(‘an event occurred!’);
    		});
    		myEmitter.emit(‘event’);
    	
    Q25-: Explain the cryptography in Node.js?

    Node.js supports cryptography through module called crypto. In this module, it provides various cryptographic functionalities like decipher, cipher, verify functions etc.

    Cryptography implementing cryptography applications is also possible with Node.js.

    It is written as-:

    Const crypto = require’crypto’;

    Const secret = ‘’;

    Const hash = crypto.createHmac(‘Ducat’).update(‘Welcome to Ducat’).digest(‘hex’);

    Console.log (hash);

    Q26-: Explain the setup of Node.js environment variable?

    Setup of Node.js environment variable is very important to run node.js.

    If you haven’t setup node.js environment variable and if you run node.js then error occurs as it command prompt shows node is not a recognized as an internal or external, it means that your computer doesn’t know that what the node stands for? Because you haven’t give any other reference what node is all about so for this you have to setup node environment variable.

    Go to ‘C’ drive and open program files here you will find folder node.js this is destination you put as an environment variable for node.js, copy destination and right click on PC and open properties, you will find advanced system setting, click on advanced system setting and in that click on environment variables button and look out for path option here and click on edit option- then click on ‘New’ and paste the destination you have copied and click on ‘OK’ twice.

    Now open the command prompt and open node.js by typing Node and then it will work. You can check by simple calculation like 2+2.

    Q27-: List down various Timing Features in Node.js?

    Timers API is most important API used in Node.js. You can use it to delay an operation by using “setTimeout” Function and you can use “setInterval” function to execute the same operation in a loop again and again after some delay.

    Now see how to use setTimeout function.

    First install node execution files in which you get 4.1 versions of timers that is 4.1 timers where you will find all the sub files on which setTimeout function runs. And another important thing is you should navigate that above respected folder in Command Prompt.

    In setTimeout function it takes two parameters in which first parameter is ‘func’ and second parameter is ‘timeinMilles’- time in milli second

    		setTimeout(func, timeinMilles);
    		Now delay function execution by 4 sec.
    		setTimeout(func, 4= 1000);
    		then define function
    		setTimeout(() => {
    		   console.log(‘Hello after 4 sec’)
    		}, 4 = 1020);
    	

    Save the file and run and see thee output after 4 sec.

    In setInterval function loop or result will be shown after specific interval.

    Set interval of 4 second-:

    		setInterval(
       		() => console.log(‘hello every 4 seconds’),
    		);
    	
    Q28-: Describe exit codes of Node.js?

    Exit codes in Node.js are set of specific codes which are used for specific process finishing. Global Objects can also be included in it. Exit codes used in Node.js are as below-:

    1. Uncaught fatal exception
    2. Unused
    3. Fatal error
    4. Internal Exception handler Run-time failure
    5. Internal JavaScript Evaluation Failure
    Q29-: Explain debugging factors in Node.js?

    There are better debugging tools for nodes that are third-party libraries mainly Visual Studio code the editor come with built-in debugger and then there’s a package called node inspector.

    On node.js site pick version and then find debugger.

    Actually debugging is all about fixing defects or errors of software. Finding errors is quite difficult for developer. Node.js has some great tools which help to trace errors.

    Debugging has its own selection on the basis of following-:

    1. Breakpoint- It is the point at which debugger stops program so its state inspected.
    2. Debugger- It is a tool by which debugging is done such as running code line by line to inspect variable states.
    3. Frequency- It tells how often and in what condition bug will occur.
    4. Log point- It is an instruction to debugger which shows the value of variable at point during its execution.
    5. Logic error- Programs works but doesn’t act as intended.
    6. Race condition- It is hard to trace the bugs depend on sequence and timing of uncontrollable events.
    7. Regression- it is all about re-emergence of previously fixed bug.
    8. Reproduce- It requires causing the errors.
    9. Step into- It is called when running code line by line in debugger.
    10. Step out- It happens when code is running line by line and execution is complete of current function and return to calling code.
    11. Step over- It calls with complete execution of command without stepping into function.
    12. Syntax error- It includes typographical errors like console.lug.
    13. Watch point- It is similar to breakpoint except stopping of program when variable set to specific value.

    Famous debugging tools which are use – Node.js debugging guide, ndb, IBM report-toolkit for Node.js, LogRocket, Sentry.io

    Q30-: Pros and Cons of Node.js and its uses.

    Node.js allows JavaScript to run on browser. Node is part of popular JavaScript centered technology stacks as- Express, Angular, and React etc.

    There are many frameworks built for node like Express JS, Meteor, Sails, and others.

    Source modules and ready-made packages you can use NPM, It is an extensive package base which helps building with stacks (MEAN AND MERN).

    Pros of node.js

    1. It inherits the merits of JS programming as well as allowing engineers to use libraries and features.
    2. Frontend and Backend are easier to keep in sync, because of a single language used on both sides of application.
    3. It becomes possible for developers to share and reuse the code.
    4. Node.js is scalable and lightweight.5) It makes easier to update as well as maintain the architecture as the services are decoupled.
    5. It’s used to compile JavaScript into machine code instead of using an interpreter.
    6. Event based nature makes node.js highly efficient for real-time apps.

    Cons of Node.js

    1. NPM registry seems to be quantity not quality driven, which is uncommon for open source project.
    2. Typical Node.js developers has 2 years of experience with Node half of their working time, few experienced developers.
    3. Immature tools

    Node.js used for -:

    1. Real time Web application
    2. Network application
    3. General purpose applications
    4. IOT applications
    5. NPM (node package manager)

    Copyright 1999- Ducat Creative, All rights reserved.