github.com/skabbes/up@v0.2.1/docs/getting-started.md (about) 1 --- 2 title: Getting Started 3 --- 4 5 The bare minimum Up application is a single file for the application itself. Up runs "vanilla" HTTP servers listening on the `PORT` environment variable, passed to it by Up. 6 7 For example create a new directory with the following `app.js` file: 8 9 ```js 10 const http = require('http') 11 const { PORT = 3000 } = process.env 12 13 http.createServer((req, res) => { 14 res.end('Hello World from Node.js\n') 15 }).listen(PORT) 16 ``` 17 18 Let Up know which ~/.aws/credentials to use, note that you may also define "myapp" to the "profile" property in `up.json`. 19 20 ``` 21 $ export AWS_PROFILE=myapp 22 ``` 23 24 Deploy it to the development stage: 25 26 ``` 27 $ up 28 ``` 29 30 Open up the URL in your browser: 31 32 ``` 33 $ up url --open 34 ``` 35 36 Or copy it to the clipboard: 37 38 ``` 39 $ up url --copy 40 ``` 41 42 Or test with curl: 43 44 ``` 45 $ curl `up url` 46 ``` 47 48 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: 49 50 ``` 51 $ up stack delete 52 ``` 53 54 If you're not a Node.js developer here are some examples in additional languages. 55 56 For Python create `app.py`: 57 58 ```python 59 from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer 60 import os 61 62 class myHandler(BaseHTTPRequestHandler): 63 def do_GET(self): 64 self.send_response(200) 65 self.send_header('Content-type','text/html') 66 self.end_headers() 67 self.wfile.write("Hello World from Python\n") 68 return 69 70 server = HTTPServer(('', int(os.environ['PORT'])), myHandler) 71 server.serve_forever() 72 ``` 73 74 For Golang create `main.go`: 75 76 ```go 77 package main 78 79 import ( 80 "os" 81 "fmt" 82 "log" 83 "net/http" 84 ) 85 86 func main() { 87 addr := ":"+os.Getenv("PORT") 88 http.HandleFunc("/", hello) 89 log.Fatal(http.ListenAndServe(addr, nil)) 90 } 91 92 func hello(w http.ResponseWriter, r *http.Request) { 93 fmt.Fprintln(w, "Hello World from Go") 94 } 95 ``` 96 97 Finally for Crystal create `main.cr`: 98 99 ```ruby 100 require "http/server" 101 102 port = ENV["PORT"].to_i 103 104 server = HTTP::Server.new(port) do |ctx| 105 ctx.response.content_type = "text/plain" 106 ctx.response.print "Hello world from Crystal" 107 end 108 109 server.listen 110 ```