- mkdir and cd into project directory
- run
npm initto createpackage.json(can also usenpm init -yto answer yes to all prompts) - install needed packages with
npm install <package name> - create a
.gitignorefile and addnode_modulesto it - make sure that
node_modulesis not being tracked by git
- Clone down the repo that you want to work with and cd into the new directory
- There should be a file called
pacakge.jsonthat contains a list of "dependencies" which are node packages the repo used - By going into our terminal and using the command
npm installin the directory of the repo, we can download all the neccessary packages to our local repo - npm is able to look at the
package.jsonfile and read the list of dependencies to install exactlly what the repo used and needs
- First, create a .js file which will contain the code for our module
- Write the code we want to export using the object
module.exports
// examples
module.exports.myFunction = () => console.log("Fetch is not happening")
module.exports.someNumbers = [39, 2, 56]
- Import the module into another .js file using the
require()function which takes the file path of the module we want as an argument
// example
const myModule = require('./myModule.js)
myModule.myFunction()
- We can use any code contained in the module by using dot notation