Have you ever needed to share your application quickly via a public URL Or you needed a public rest API to integrate with apps like Slack, Telegram of many others?

If yes, I would like to share with you my latest discovery:

I will demonstrate how easy to use this tool is by showing you three classic use cases. First of all, create an account (for free) and install the desktop app that comes also with CLI support. Once you have it installed follow these instructions:

# Let's create a roor project for out tests
mkdir testing-now && cd testing-now

# Inside it we will create a folder for the first use case
mkdir static-website && cd static-website

# Let's create an awesome html web page 
echo "<h1>Hello World</h1>" > index.html

# Run the now command
now --public

Once the last command is completed, you will get already in your clipboard the public where you can see your webpage

Now uses the folder name as the project name and creates an instance for each deploy and versions it with a specific hash: uafovxlpvg

Another nice discovery for me was to see that it delivers the app over https. As I was building a bot for the application Telegram, it’s API requires that it communicates only over https. Without having to middle around with certificates, now had this functionality build out of the box.

Let’s continue to the second example:

# Go to the root project and create a new folder
cd ~/testing-now

mkdir node-app && chdir node-app

# Let's create a standard express app
npm init

npm install express --save

Create a file called index.js:

const express = require('express')
const app = express()

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(3000, () => console.log('Example app listening on port 3000!'))

Check that your package.json contains a start script:

{
  "name": "app",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.3"
  }
}

Run again the now --public command and you will have now a public accessible node app. In my case https://app-wzjjetdmmx.now.sh/. Like before, Now scanned the contents of the folder, detected the package.json file, created an instance using the app name and versioned it with a new hash.

For the last example, we need to go back to the root project and create a new folder

# Go to the root project and create a new folder 
cd ~/testing-now

mkdir docker-app && cd docker-app

Create a new file called server.go:

package main

import (
    "fmt"
    "net/http"
)

func handler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello World! How are you today %s!", r.URL.Path[1:])
}

func main() {
    http.HandleFunc("/", handler)
    fmt.Println("Server running...")
    http.ListenAndServe(":8080", nil)
}

 

Create a Dockerfile with this content:

FROM golang:1.8

WORKDIR /go/src/app
COPY . .

RUN go get -d -v ./...
RUN go install -v ./...

EXPOSE 8080

CMD ["app"]

Once you run the now --public command you will have, out of the box,  a complete docker container running and available on a public URL. You can decide what programming language to use, what image from docker hub fits better your needs, but the possibilities are amazing.

You can use any of the images available on docker-hub, meaning you can build an application on go, on python or any other language that you want.

Amazon AWS and Google App Engine offer similar service, but what impressed me the most at Now is the simplicity of the whole process. I can’t tell you how many times I got lost in the Amazon AWS UI or triggered the wrong command…

I think the guys at Now did a terrific job and they have my appreciation. Their free tier is perfect for testing, prototyping and creating proof of concepts. If you want to scale your idea they also offer suitable packages and great support. My recommendation to all of you to give it a try and here are some additional resources on what else you can do with now:

Andrei

read more

LEAVE A REPLY

This site uses Akismet to reduce spam. Learn how your comment data is processed.