Dependency Management - OCLC-Developer-Network/devconnect2018-idm GitHub Wiki
- We'll be using a tool called NPM to manage our project's dependencies. By "dependencies" we mean the code libraries and other external resources that our project requires in order to run. This includes the OCLC PHP Authentication Library, the MVC framework Slim, the MARC record parser we'll need, and so on.
- In your project file, create a file called
package.json
.
$ touch package.json
- Open
package.json
in your text editor.
- Add the following
{
"name": "devconnect_2018_userinfo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
},
"keywords": [],
"author": "",
"license": "Apache 2.0",
"devDependencies": {
"chai": "^4.1.2",
"cucumber": "^4.0.0",
"cucumber-mink": "^2.0.0",
"mocha": "^5.0.1",
"moxios": "^0.4.0",
"nodemon": "^1.17.1"
},
"dependencies": {
"axios": "^0.17.1",
"body-parser": "^1.18.2",
"ejs": "^2.5.7",
"express": "^4.16.2",
"js-yaml": "^3.10.0",
"nodeauth": "git+https://github.com/OCLC-Developer-Network/oclc-auth-node.git"
}
}
- Save the file.
- Create the following directories:
$ mkdir src
$ mkdir views
$ mkdir test
- Run NPM to install your dependencies:
$ npm install
- Now, we want to commit our
package.json
file to our GitHub repository, but there is some prep we must do first. You'll notice that the command in the previous step created a /node_modules/
directory in your project that contains all of the external resources you installed. We do not want to put these files in version control.
- To tell git to ignore the
/node_modules/
directory, create a .gitignore
file:
$ touch .gitignore
- Open
.gitignore
in your text editor.
- Add the following lines
- (This includes a few resources other than
/node_modules/
, but we'll get to those later. :wink:)
/node_modules/
/.project
/config.yml
- Save the file.
- We're now ready to commit our changes to GitHub. To view local changes not yet commited, enter this command:
$ git status
- This command should output text telling you that your composer.json and .gitignore files are not yet committed.
- Add these files to the repository:
$ git add --all
- Commit your changes:
$ git commit -m "added package.json and .gitignore"
- In between the quotes, you can enter whatever description of the changes you would like.
- Push your changes to your remote repository:
$ git push origin master