You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create a file called "package.json" with the following contents;
54
53
55
-
~~~json
54
+
```json
56
55
{
57
56
"name": "hello-node",
58
57
"version": "0.0.1",
@@ -63,53 +62,52 @@ Create a file called "package.json" with the following contents;
63
62
"node": "0.8.x"
64
63
}
65
64
}
66
-
~~~
65
+
```
67
66
68
67
This file tells node which libraries are in use (express, in this case) and what versions to use. The engines configuration can also be used to specify which version of node to use, although this is also selected using VMC when deploying the application. For a more detailed explanation of package.json, take a look at https://npmjs.org/doc/json.html
69
68
70
69
## <aid='dependencies'></a>Dependencies, NPM and package.json ##
71
70
72
71
Install the modules declared as dependencies in package.json using NPM
73
72
74
-
~~~console
73
+
<preclass="terminal">
75
74
$ npm install
76
-
~~~
75
+
</pre>
77
76
78
77
This should create a "node_modules" folder that contains the application's dependencies.
79
78
80
79
Start the application as a local and server and check it's output
81
80
82
-
~~~console
81
+
<preclass="terminal">
83
82
$ node app.js
84
-
~~~
83
+
</pre>
85
84
86
85
Open a browser and navigate to http://localhost:3000, or, alternatively use "curl" in another shell
87
86
88
-
~~~console
87
+
<preclass="terminal">
89
88
$ curl http://localhost:3000
90
-
~~~
89
+
</pre>
91
90
92
91
You should see the output - "Hello from Cloud Foundry"
93
92
94
93
## <aid='deploy-your-app'></a>Deploying your application ##
95
94
96
95
With VMC installed, target your desired Cloud Foundry instance and login
97
96
98
-
~~~console
97
+
<preclass="terminal">
99
98
$ vmc target api.cloudfoundry.com
100
99
Setting target to https://api.cloudfoundry.com... OK
101
100
102
101
$ vmc login
103
-
~~~
102
+
</pre>
104
103
105
104
Deploy the application by using the "push" command, notice the URL "hello-node.cloudfoundry.com" was taken, so it was changed to hello-node2.cloudfoundry.com
106
105
All the other options were left as the default by pushing enter.
107
106
108
-
~~~console
107
+
<preclass="terminal">
109
108
$ vmc push
110
109
111
110
Name> hello-node
112
-
113
111
Instances> 1
114
112
115
113
1: node
@@ -157,22 +155,22 @@ Save configuration?> n
157
155
Uploading hello-node... OK
158
156
Starting hello-node... OK
159
157
Checking hello-node... OK
160
-
~~~
158
+
</pre>
161
159
162
160
Finally check your application has deployed correctly, navigating to the configured URL.
163
161
164
162
## <aid='checking-node-versions'></a>Node.js version parity ##
165
163
166
164
It's important to make sure that the version of Node.js used on your computer is the same as the version you use when deploying to Cloud Foundry. Check your local version, like so;
167
165
168
-
~~~console
166
+
<preclass="terminal">
169
167
$ node -v
170
168
v0.8.2
171
-
~~~
169
+
</pre>
172
170
173
171
In this instance you can see the installed version is 0.8.2, so when deploying we would select "node08" for the runtime. To see a list of available runtimes using VMC, use the following command;
174
172
175
-
~~~console
173
+
<preclass="terminal">
176
174
$ vmc info --runtimes
177
175
178
176
Getting runtimes... OK
@@ -185,7 +183,7 @@ node06 0.6.8
185
183
node08 0.8.2
186
184
ruby18 1.8.7p357
187
185
ruby19 1.9.2p180
188
-
~~~
186
+
</pre>
189
187
190
188
## <aid='next-steps'></a>Next steps - Binding a service ##
0 commit comments