1. Explain the purpose of ExpressJS package?
Express.js is a light-weight web application framework to help organize your web application into an MVC architecture on the server side.
2. What is the use of NODE_ENV?
NODE_ENV is an environment variable used by the express webserver framework.
When a node application is in run, you can check the value of the environment variable and do different things based on the value.
NODE_ENV specifically is used to check whether a particular environment is a production or a development environment.
Access using process:
process.env.NODE_ENV
Access using Express:
app.get('env')
3. How Many Types Of Streams Are Present In Node.Js?
There are four types of streams −
Readable − Stream which is used for read operation.
Writable − Stream which is used for write operation.
Duplex − Stream which can be used for both read and write operation.
Transform − A type of duplex stream where the output is computed based on input
4. Write a simple code to enable CORS in Node js?
CORS stands for Cross-Origin Resource Sharing. It a is a mechanism that uses additional HTTP headers to tell a browser to let a web application running at one origin (domain) have permission to access selected resources from a server at a different origin.
Use below code to enable CORS on NodeJS
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
5. What do you understand by a test pyramid?
unit testing rule of thumb in Node.js,
The test pyramid describes that you should write unit tests, integration tests and end-to-end tests as well. You should have more integration tests than end-to-end tests, and even more unit tests.
6. What modules Used for Node.js Unit Testing
For unit testing, we are going to use the following modules:
test runner: mocha, alternatively tape
assertion library: chai, alternatively the assert module (for asserting)
test spies, stubs and mocks: sinon (for test setup).
7. List out some new features introduced in ES6?
Following are the list of few new Features introduced in ES6
- const and let keywords
- Array helper functions like map, forEach, filter, find, every, some, reduce
- Arrow functions
- Classes and enhanced object literals
- Template strings
- Default function arguments
- Rest and spread operators
- Promises
- Modules
- Multi-line Strings
- Destructuring Assignment
8. what is Closures?
A Closure is a function defined within another scope that has access to all the variables within the outer scope. Global variables can be made local (private) with closures.
9. Why Zlib is used in Node js ?
Zlib is a module in Node.js responsible for compression and decompression (Like Zip and UnZip) functionality.
It does so by using Gzip and Deflate/Inflate, as well as Brotli.
The process of Compressing/decompressing a stream (such as a file) can be achieved by piping the source stream data through a zlib stream into a destination stream.
10. What IDEs Can You Use For Node.Js Development?
Visual Studio Code
Sublime Text
WebStorm
Atom
Cloud9
Eclipse
IntelliJ IDEA