|
1 | 1 | # getting-started-nodejs |
2 | 2 |
|
3 | | -Node.js sample application for wercker built with Express |
| 3 | +[](https://app.wercker.com/project/bykey/7b1a402dd00d57fc9abddf9eb5161675) |
4 | 4 |
|
5 | | -Uses the default Node.js [Docker container](https://registry.hub.docker.com/u/library/node/) from the Docker Hub. |
| 5 | +A sample application in Javascript on NodeJS for Wercker. |
6 | 6 |
|
7 | | -Note: this sample application only runs on the Ewok stack on wercker |
| 7 | +This application uses the `node` container obtained from the [Docker Hub](https://hub.docker.com/_/node/) |
8 | 8 |
|
9 | | -[](https://app.wercker.com/project/bykey/7b1a402dd00d57fc9abddf9eb5161675) |
| 9 | +## Setup |
| 10 | +Clone this repo and cd into the directory: |
| 11 | + |
| 12 | +``` |
| 13 | +git clone https://github.com/wercker/getting-started-nodejs.git |
| 14 | +cd getting-started-nodejs |
| 15 | +``` |
| 16 | + |
| 17 | +## Running |
| 18 | +You can run the sample app in a couple of different ways. The first is to simply launch the executable: |
| 19 | +``` |
| 20 | +node app.js |
| 21 | +``` |
| 22 | + |
| 23 | +Now point your browser at `http://localhost:8080` to see: |
| 24 | +``` |
| 25 | +{"cities":["San Francisco","Amsterdam","Berlin","New York","Tokyo"]} |
| 26 | +``` |
| 27 | + |
| 28 | +The second, and more useful, way is to use the `wercker dev` command to launch the binary within a Docker container, using the base image defined in the `box/id` property at the top of the `wercker.yml`, like so: |
| 29 | +``` |
| 30 | +wercker dev --expose-ports |
| 31 | +``` |
| 32 | +The `dev` target inside `wercker.yml` uses the `internal/watch` step to dynamically reload the runtime container when sourcefile changes are detected, which allows you to quickly test changes without having to kill/rebuild/relaunch the container. For instance, add another city to the array on `app.js:6' like so: |
| 33 | + |
| 34 | +``` |
| 35 | +res.write(JSON.stringify({"cities" : ["San Francisco", "Amsterdam", "Berlin", "New York", "Tokyo", "London"]})); |
| 36 | +``` |
| 37 | + |
| 38 | +and then refresh your browser pointing to `http://localhost:8080` to see: |
| 39 | +``` |
| 40 | +{"cities":["San Francisco","Amsterdam","Berlin","New York","Tokyo","London"]}} |
| 41 | +``` |
10 | 42 |
|
11 | 43 | --- |
12 | | -Sign up for wercker [here](http://wercker.com) |
13 | | -Learn more on our [dev center](http://devcenter.wercker.com) |
| 44 | +Sign up for Wercker: http://www.wercker.com |
| 45 | + |
| 46 | +Learn more at: http://devcenter.wercker.com |
0 commit comments