To know what we have access to with built-in node packages, we need to know what node version our environment is running in: - node --version
- take a look at the docs: NodeJS Docs
fs
(file system) - reading and writing filespath
- manipulating file pathsreadline
- reading data from somewhere else (like a file) line-by-lineconsole
- the console objectprocess
- the object representing the running programFor more information about these packages, see here: Built-in Node Packages. You will not be tested on this information for the assessment!!
npm
What is npm
? - npm
is a package manager that allows us to use bundled code written by other people and available on the npm online registry - it’s also a cli
(command line) tool that we can use to interact with the npm online registry
root
application folder - contains all your app’s files - includes npm requirements
package.json
file - exists at the top of the root
application folder - contains metadata - info about the project - contains scripts - commonly used commands in the project) - contains dependencies - other packages and their versions that your project relies on - safe to edit but be careful of using json
syntax!
package-lock.json
file - exists at the top of the root
application folder - contains exact details about installed dependencies and their versions - represents an exact reproducible npm environment - do not edit!
node_modules
folder - includes subdirectories for each dependencies - also includes dependencies of dependencies! Every package you need should be here - Don’t include in git version control system make sure to .gitignore this folder
npm
Commandsnpm
will show npm’s help info, including some common commands and how to access more detailed guides.
npm init
will set your current project directory up for npm. This requires answering a few questions to generate a package.json
file, a critical part of npm’s dependency management functionality. (npm init --y
will skip those questions and make a generic package.json
for you.)
npm install
will download and install a package into your project. You can use the -g
(or --global
) flag to install a package for use everywhere on your system.
npm install -g cowsay
. Once the download’s completed, try running cowsay Hello, world!
.npm
installs packagesnpm install {PACKAGE NAME HERE}
.package.json
file to include the package as a dependency and requests the package from the npm registry.node_modules
folder in your current directory (one will be created if it’s not already there). It chooses the most recent version by default.package-lock.json
file that includes where the installed package is located and exactly which version was used.require('your-package-name-here');
anywhere in your project..gitignore
A .gitignore
file allows us to tell git
which files and directories to never include in our working directory and to never commit to our git logs.
The node_modules
folder created by npm install
contains massive amounts of files that we don’t want to be committing and tracking. - npm
is a version-controlled package manager already so we don’t need to track changes to the code in the node_modules
folder. - We only need to commit the versions of the packages we are using specified in the package.json
and the package-lock.json
files.
npm
Lesson Learning Objectives