Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

in less than 30 minutes? Let's do it, I wanna see it


Took me around 15 minutes in total. Can I be CTO at your silicon valley company now with 500k salary?

    const express = require('express')
    const app = express()
    const puppeteer = require('puppeteer')
    const uuidv1 = require('uuid/v1')
    const fs = require('fs')
    const validUrl = require('valid-url')

    app.get('/', function (req, res) {
      (async () => {
        const url = req.query.url;

        if (!url) {
          return res.send({error: 'Need to specify url param e.g. ?url=https://google.com/'});
        }

        if (!validUrl.isUri(url)) { // Also protects against file://...
          return res.send({error: 'url not valid'})
        }

        const id = uuidv1();
        const browser = await puppeteer.launch();
        const page = await browser.newPage();
        await page.setViewport({ width: 1920, height: 1080})
            
        await page.goto(url)
        const buffer = await page.screenshot({path: id + '.png'})

        const fullPath = __dirname + '/' + id + '.png';

        res.sendFile(fullPath, function () {
          fs.unlink(fullPath)
        })

        await browser.close()
      })();
    })

    app.listen(3000, function () {
      console.log('Example app listening on port 3000!')
    })


Apart from the smugness, I hope you realize that technology != success. It doesn't matter that I can replicate Tinder with a few weeks of coding.

In fact, the two are often inversely correlated because engineers can be so worried about what technology, what stack, what language, instead of worrying about the real deal: getting the users.


I know that you can build twitter and tinder and getting the users is hard. But my point was very different -- People will probably need this for some internal tooling (devops) and it is simple enough to just build it on your own without paying someone or relying on 3rd party.

IMO there should be a line of what to outsource and what to build yourself. In my mind simple things like this go into second category.


I see your point but I'm not fully convinced. Companies outsource simple stuff all the time. To wit, I think that line you drew might vary from company to company.


Don't run this on EC2; you'll probably get your metadata stolen. Also:

    if (!validUrl.isUri(url)) { // Also protects against file://...
It does?

    ▶ cat valid.js
    var validUrl = require('valid-url');

    if (validUrl.isUri("file:///etc/passwd")){
        console.log('Looks like a URI');
    }

    ▶ node valid.js
    Looks like a URI
Perhaps the problem requires a little more than 15 minutes to do well :)


Yeah, like 15 minutes more. Ergo my original statement - 30 minutes. As a bonus I would also stream binary data directly to client without creating an image file.


ok. congrats! While I would spend a few hours you would spend 30 minutes. However, this guy just published something to start making money, and it's working for him, no matter who is able to create what in how much time.


> Took me around 15 minutes in total.

So assuming a rate of $80/hr (which is on the low-side), it cost you $20 in time to do what you could have for $7.

A CTO worth 500k/year would probably realise that paying $7 is more cost effective.


5 mins would be enough with puppeteer https://github.com/GoogleChrome/puppeteer


Basically you just need to read up on how chrome-headless works.. I do have this complicated chrome-remote-protocol script that does the same as the command line version, so I guess it's all about priorities

Basically:

  1. sign up for droplet 10 min
  2. install google-chrome and webserver 10 min
  3. call google headless from a CGI script 10 min




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: