github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/examples/hello/node/README.md (about)

     1  ## Quick Example for a NodeJS Function (4 minutes)
     2  
     3  This example will show you how to test and deploy a Node function to IronFunctions.
     4  
     5  ```sh
     6  # create your func.yaml file
     7  fn init <YOUR_DOCKERHUB_USERNAME>/hello
     8  # build the function
     9  fn build
    10  # test it
    11  cat hello.payload.json | fn run
    12  # push it to Docker Hub
    13  fn push
    14  # Create a route to this function on IronFunctions
    15  fn routes create myapp /hello
    16  ```
    17  
    18  Now surf to: http://localhost:8080/r/myapp/hello
    19  
    20  ## Dependencies
    21  
    22  Create a [package.json](https://docs.npmjs.com/getting-started/using-a-package.json) file in your functions directory.
    23  
    24  Run:
    25  
    26  ```sh
    27  docker run --rm -v "$PWD":/function -w /function iron/node:dev npm install
    28  ```
    29  
    30  Then everything should work.
    31  
    32  For example, using the `package.json` file in this directory which includes the [request](https://www.npmjs.com/package/request) package, you can add this to func.js and it will work:
    33  
    34  ```js
    35  var request = require('request');
    36  request('http://www.google.com', function (error, response, body) {
    37    if (!error && response.statusCode == 200) {
    38      console.log(body) // Show the HTML for the Google homepage.
    39    }
    40  })
    41  ```