hosting for node.js is still not very widespread, especially in the german-speaking world. here, the american cloud company heroku offers a remedy - and even for free. you always notice the paradigm "build apps... not infrastructure" and yet you have hardly any restrictions. we implement a small cronjob based on phantomJS as an example, which scans a website every day and sends the page title via email.
To do this, we first register free of charge at https://signup.heroku.com/:
After the obligatory e-mail confirmation, we will issue a secure password:
In order to be able to use free add-ons from the Marketplace later, we first have to verify our account under https://heroku.com/verify by entering a credit card (don't worry, everything remains free):
The rest now takes place exclusively on the command line. For this we need locally Node.js / npm , Git and Heroku CLI .
We finally log in (once) locally to Heroku on the command line:
First we create a new app based on a suitable buildpack . In our example we are using the official Node.js buildpack heroku-buildpack-nodejs.git:
1a01abaf4b9308c5714622396ccc4708
Now we create a package.json to install the packages PhantomJS, CasperJS, SpookyJS and Nodemailer, which we need for our project:
1a01abaf4b9308c5714622396ccc4708
The actual logic can be found in script.js:
1a01abaf4b9308c5714622396ccc4708
We first test everything locally:
1a01abaf4b9308c5714622396ccc4708
The script extracts a title from a website and sends an email:
We now push everything on Heroku that triggers the build process:
1a01abaf4b9308c5714622396ccc4708
If you want to push code changes to Heroku later on, you just push again and we can now check via SSH if everything is running on the server:
1a01abaf4b9308c5714622396ccc4708
Here, too, the email is sent correctly. Now we just have to automate the process:
1a01abaf4b9308c5714622396ccc4708
We add a new script call with "Add new job:
As frequency we select every 10 minutes as a test and save:
The cronjob will now automatically do its job.