-
Notifications
You must be signed in to change notification settings - Fork 3
/
dependencies.html.md.erb
76 lines (63 loc) · 2.91 KB
/
dependencies.html.md.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
---
title: Declare App Dependencies
owner: Tobias Fuhrimann
---
<strong><%= modified_date %></strong>
<%= vars.product_short %> recognizes an app as Node.js by the existence of a `package.json` file in the root directory. For your own apps, you can create one by running `npm init`.
The demo app you deployed already has a `package.json`, and it looks something like this:
```json
{
"name": "cf-sample-app-nodejs",
"description": "A sample Node.js application to run on Cloud Foundry out of the box",
"keywords": [
"cloud-foundry"
],
"version": "0.0.0",
"private": true,
"author": "Tobias Fuhrimann <tobias.fuhrimann@swisscom.com>",
"license": "ISC",
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.0",
"cookie-parser": "~1.4.1",
"debug": "~2.2.0",
"express": "~4.13.4",
"morgan": "~1.7.0",
"pug": "^2.0.0-alpha3",
"serve-favicon": "~2.3.0"
},
"engines": {
"node": ">=4.4.2"
},
"repository": {
"type": "git",
"url": "https://github.com/swisscom/cf-sample-app-nodejs.git"
},
"bugs": {
"url": "https://github.com/swisscom/cf-sample-app-nodejs/issues"
}
}
```
The `package.json` file determines both the version of Node.js that will be used to run your application on <%= vars.product_short %>, as well as the dependencies that should be installed with your application. When an app is deployed, <%= vars.product_short %> reads this file and installs the appropriate node version together with the dependencies using the `npm install` command.
Run this command in your local directory to install the dependencies, preparing your system for running the app locally:
<pre class="terminal">
$ npm install
cf-sample-app-nodejs@0.0.0 /.../cf-sample-app-nodejs
├─┬ body-parser@1.15.0
│ ├── bytes@2.2.0
│ ├── content-type@1.0.1
...
</pre>
Once dependencies are installed, you will be ready to run your app locally.
Upon running `cf push`, we will also push our whole dependencies folder `node_modules`. Since Cloud Foundry runs `npm install` anyways, this is redundant and should be omitted to save bandwidth and even more importantly: time. You can create a `.cfignore` file which works just like a `.gitignore` file and which tells Cloud Foundry what files should be excluded when pushing. Let's create a `.cfignore` file and exclude the `node_modules` folder:
```txt
node_modules
```
<p class="note">
<strong>Pro Tip</strong>: To lock down your dependencies' versions before pushing, you can run <code>npm shrinkwrap</code>. This will create a <code>npm-shrinkwrap.json</code> file which holds the exact versions of all your dependencies. Any <code>npm install</code> will then install exactly these versions so you can be sure that your app is using versions which work.
</p>
<div style="text-align:center;margin:3em;">
<a href="./run-locally.html" class="btn btn-primary">I've installed the App dependencies locally</a>
</div>