Software engineer, data guy, Open Source enthusiast, New Hampshire resident, husband, father. Fan of guitars, hiking, photography, homebrewing, sarcasm.
In my first blog post about NodeJS, I thought it would neat to utilize PhantomJS to fetch a URL, take a screenshot, and serve it back to the user as a static asset.
Install NodeJS & PhantomJS via brew, if you haven’t already:
Create a new directory, and define a new file: package.json, contents:
Install dependencies:
I used Express to handle the routes and serve static assets, and Jade as the HTML middleware.
I create a views subdirectory for Jade with a new layout, file: views/layout.jade
And another view file for the index page, which creates a form with an input element for URL. file: views/index.jade.
I then created the main app file “app.js” to run the server.
Start the app. Browse to http://localhost:3000 and submit a URL.