Node.js Basic Questions

I would like to share some NodeJS Basic questions to clear the NodeJS concepts.

How NodeJS works?

NodeJS provides the runtime environment and execute the JavaScript code. Basically, NodeJS is a JavaScript engine name as Chrome V8. It allows running the Javascript on back-end. Node.js V8 engine work as single thread means that run the code synchronously. Node.js is based on an event-driven architecture.

What is the npm?

Node Package Manager (npm) is the biggest JavaScript libray repository, host by www.npmjs.com. It manages the dependencies of open-source javascript packages which are mention in the package.json file. CLI command ‘npm install’ download all packages on the node_modules folder.

How npm install works?

‘npm install’ command read the dependencies from the package.json file and download the all dependencies (javascript libraries) under the node_modules subfolder and also insert the dependency entry in the package.json file (if you give the library name like npm install xyz). If you run the command with -g then it will download the library folder under the global location and don’t put the entry in the package.json file.

What is the ng build ?

Basically “ng build” is Angular CLI command to bundle the angular app into a ‘dist’ folder.

How node_modules works?

All NodeJS built-in or installed modules/libraries/dependence are present in node_modules (core module) folder. These java-script/json etc files are created (downloaded) by the help of package.json or package-lock.json file (present in the project root directory). These modules are called/load by require(‘module name’) or import syntax. Module should have index.js file. nodule_modules folder should not be present in the source code.

What is the polyfills.js?

Polyfills uses to compatible with different browsers.To include the polyfill you need to require it at the top of the entry point to your application.

What is npm audit fix?

To find the vulnerabilities ‘npm audit’ command scan the all packages/dependencies (which are mention in package.json) in node_modules folder. npm audit fix command uses to fix the vulnerabilities.

What is the nodemon?

To avoid the restart node server after edit the code in file. nodemon watches the changes and restart the server automatically.

Why Express module is used in NodeJS?

Express is a very popular lightweight web framework (Back-end) for NodeJS. It is used in a very simple and systematic way to create web servers. It is also used to make REST APIs. It works with a combination of other modules or frameworks in NodeJS.

Why do use npm init command?

It uses for create the package.json file.