NPM, or Node Package Manager, helps us utilze 3rd party packages.
These packages will help us solve many problems that developers regularly come up against.
In terminal, if we navigate to our project folder, we can run
npm init -y
This will create a
package.json file for us. This file offically makes the project a node module, and will contain meta information about our project, including what packages we used.
We can run
npm install [package name] any time to install npm packages locally, to the specific project that we're working on.
Still in your project folder, watch your
package.json file as you run
npm install readline-sync.
It adds a
dependencies section, and puts readline-sync and the proper version in
This will be helpful when you or other developers clone down your project from github.
More importantly, it gives us the
node_modules folder and adds the readline-sync package to it.
Our file structure will now look like:
project/ /node_modules/ /readline-sync/ app.js package.json
Remember to put
/node_modules in your git repo's
The last thing we need to do before using methods from the helpful third party package is to import it into our file using
const readline = require("readline-sync")
Here is one example from the docs, check them out for more cool methods from readline.
const userName = readline.question('May I have your name? '); console.log('Hi ' + userName + '!');
npm init -y - Run this command in your project folder to make it a node module
npm install [package name] - Run this command in your project folder to install a local npm package.