1. Differentiate between readFile vs createReadStream in Node.js
It reads the file and returns the complete data at one time, when it completes the full reading of the file, till the time it saves the whole data in its memory.
It needs more size of memory compared to another one.
In this case user have to wait until the completions of full reading task.
It sends data in delay.
It also reads the file, but it returns the data in chunks rather than returning all at one time.
It takes less size of memory compared to first one.
In this case users get the steaming data, so user don't have to wait for long.
It sends data faster as it sent out in chunks.
2. Explain the concept of Punycode in Node.js?
Punycode is an encoding syntax.
It is used to convert Unicode (UTF-8) string of characters into basic ASCII string of characters.
As host names only understand the ASCII characters so Punycode is used to convert.
It is used as an internationalized domain name (IDN or IDNA).
3. Is cryptography supported in Node.js?
Yes, Crypto module supports cryptography in Node.js.
4. Explain the reason as to why Express ‘app’ and ‘server’ must be kept separate?
To increase the optimization, we prefer to keep Express ‘app’ and ‘server’ separate.
It encapsulates your API logical, which is your data abstraction.
This is where you should keep up your DB logic or data models.
Its sole responsibility is to keep the app/website running.
5. Explain the purpose of module.exports
When dividing your program code over the multiple files, module.exports is used to publish variables and functions to the consumer of a module.
The require() call in the source file is replaced with corresponding module.exports loaded from the specified module.
6. What tools can be used to assure consistent style? Why is it important?
Available Tools List:
It is important because these tools are very helpful when developing code in teams, to enforce a given style guide and to catch common errors using static analysis.
7. When should you npm and when yarn?
It can be used for all Node.js versions.
It is slower than Yarn.
It offers shrinkwrap CLI command to lock down the versions of package’s dependencies (npm-shrinkwrap.json)
When using Node.js version above 5.
Yarn caches all installed packages.
Yarn is installing the packages simultaneously.
It is faster than NPM.
It generates yarn.lock to lock down the versions of package’s dependencies by default.
8. What's most used HTTP framework and why?
Express.js and Sails.js
9. How can you secure your HTTP cookies against XSS attacks?
When using express we can consider following things:
Don’t use deprecated or vulnerable versions of Express
Prevent brute-force attacks against authorization
Ensure your dependencies are secure
Avoid other known vulnerabilities
10. How can you make sure your dependencies are safe?
By automate the update / security audit of the dependencies by following methods or tools:
npm outdated - npm outdated / npm outdated -g --depth=0 / npm audit / npm audit fix
Trace by RisingStack