github.com/orangenpresse/up@v0.6.0/docs/03-getting-started.md (about)

     1  ---
     2  title: Getting Started
     3  ---
     4  
     5  The simplest Up application is a single file for the application itself, with zero dependencies, and an `up.json` file which requires only a `name`.
     6  
     7  If the directory does not contain an `up.json` file, the first execution of `up` will prompt you to create it, or you can manually create an `up.json` with some preferences:
     8  
     9  ```json
    10  {
    11    "name": "appname-api",
    12    "profile": "companyname",
    13    "regions": ["us-west-2"]
    14  }
    15  ```
    16  
    17  Up runs "vanilla" HTTP servers listening on the `PORT` environment variable, which is passed to your program by Up. For example create a new directory with the following `app.js` file:
    18  
    19  ```js
    20  const http = require('http')
    21  const { PORT = 3000 } = process.env
    22  
    23  http.createServer((req, res) => {
    24    res.end('Hello World from Node.js\n')
    25  }).listen(PORT)
    26  ```
    27  
    28  Deploy it to the staging environment:
    29  
    30  ```
    31  $ up
    32  ```
    33  
    34  Open up the URL in your browser:
    35  
    36  ```
    37  $ up url --open
    38  ```
    39  
    40  Or copy it to the clipboard:
    41  
    42  ```
    43  $ up url --copy
    44  ```
    45  
    46  Or test with curl:
    47  
    48  ```
    49  $ curl `up url`
    50  ```
    51  
    52  That's it! You've deployed a basic Up application. Note that the first deploy may take a minute to set up the resources required. To delete it and its resources, use the following command:
    53  
    54  ```
    55  $ up stack delete
    56  ```
    57  
    58  If you're not a Node.js developer here are some examples in additional languages.
    59  
    60  For Python create `app.py`:
    61  
    62  ```python
    63  from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
    64  import os
    65  
    66  class myHandler(BaseHTTPRequestHandler):
    67    def do_GET(self):
    68        self.send_response(200)
    69        self.send_header('Content-type','text/html')
    70        self.end_headers()
    71        self.wfile.write("Hello World from Python\n")
    72        return
    73  
    74  server = HTTPServer(('', int(os.environ['PORT'])), myHandler)
    75  server.serve_forever()
    76  ```
    77  
    78  For Golang create `main.go`:
    79  
    80  ```go
    81  package main
    82  
    83  import (
    84    "os"
    85    "fmt"
    86    "log"
    87    "net/http"
    88  )
    89  
    90  func main() {
    91    addr := ":"+os.Getenv("PORT")
    92    http.HandleFunc("/", hello)
    93    log.Fatal(http.ListenAndServe(addr, nil))
    94  }
    95  
    96  func hello(w http.ResponseWriter, r *http.Request) {
    97    fmt.Fprintln(w, "Hello World from Go")
    98  }
    99  ```
   100  
   101  Finally for Crystal create `main.cr`:
   102  
   103  ```ruby
   104  require "http/server"
   105  
   106  port = ENV["PORT"].to_i
   107  
   108  server = HTTP::Server.new(port) do |ctx|
   109    ctx.response.content_type = "text/plain"
   110    ctx.response.print "Hello world from Crystal"
   111  end
   112  
   113  server.listen
   114  ```