NodeJS Basics Flashcards
What is the purpose of the package.json file?
This file contains metadata for the project, such as the name, version, dependencies (libraries), and so on. Given a package.json file, other people can download and install the same libraries and run tests in the same way that the original creator did.
Why is it not recommended to save and share the node_modules folder?
because it contains a large number of files, can be platform-specific, and the package.json
file already lists dependencies for easy installation.
What key advantage does it offer in terms of programming languages?
Using the same programming language for both frontend and backend.
What is the purpose of Node.js
Allows running JavaScript code on the server-side.
What command do you use to run a Node.js application from the command line?
node [file.js]
How do you access the Node.js REPL environment, and what does REPL stand for?
Open a terminal and type node
to access the Node.js REPL environment. REPL stands for “read, evaluate, print, and loop”.
Syntax for installing modules with NPM?
npm install [module_name]
installs external modules
What is one of the core tasks of Node.js in the backend of web applications?
handle HTTP requests.
primary tasks of NPM?
Managing, downloading, and installing external modules into projects or the operating system.
How do you initiate a Node repository using NPM?
npm init
(to initialize a Node repository)
What is the purpose of npm init?
npm init
is used to initialize a Node.js project and create a package.json
file to manage project details and dependencies.
What does npm init create upon execution?
npm init
creates a package.json
file that contains metadata about the project, including its name, version, description, and more.
Can you customize the initialization process with npm init?
Yes, you can provide flags like --yes
or -y
to skip the prompts and accept default values, or use -f
to force initialization without prompts.
What’s inside the node_modules folder, and why is it better not to share it?
The node_modules folder stores library code from online places. It’s smarter to list libraries in package.json and use NPM to get them. This is easier and less error-prone as you don’t need to store and manage the libraries yourself.
How can another user use the package.json file to get libraries, and why is it better?
They run npm install
on their computer, and NPM sets up a node_modules folder with dependencies from package.json. This avoids tracking all the files and versions separately in version control.