     new Promise (f, r) ->
         request url, (err, response, body) ->
             if err
-                console.error err
                 r err
-                return
             $ = cheerio.load body
             content = $('#content')
             name = content.find('h1').text()

                fs.writeFileSync filename, JSON.stringify []
                postedPets = []
        catch err
            console.error err
            r err
        get_data().then (pets) ->
            notPostedPets = []

###

# Return all pets
app.get '/', (req, res) ->
    get_data()
        .then (pets) ->
            res.json pets
        .catch (err) ->
            console.error err
            res.status(500).json(err);

# Return a random pet
app.get '/random', (req, res) ->
    get_notPostedPet()
        .then (pet) ->
            res.json pet
        .catch (err) ->
            console.error err
            res.status(500).json(err);

server = app.listen 3000, 'localhost', ->
    host = server.address().address
