In this tutorial, we will implement a simplified version of Doge Weather. http://dogeweather.com/
We will be using Node.js, a JavaScript platform for building web apps. We will then upload the web app to Heroku, a free hosting service.
- Download link available here: https://nodejs.org/en/download/
- Follow the instructions to set up a simple Hello World program: http://blog.gvm-it.eu/post/20404719601/getting-started-with-nodejs-on-windows
- Once you've successfully installed Node.js and have run your Hello World program, move on to the next step.
Nodejs is a whole topic in itself. It is covered well here by Daniel Shiffman . In the Youtube URL, there is a written guide there that is very helpful.
- https://signup.heroku.com/
- Login to your Heroku account and go to the Dashboard
- Go to the setup and follow the steps on that page.
- Go to Github and create a new repository. Download to the desktop.
- Open command shell/line and navigate to your repository
- type
npm initto create the 'package.json' and intialize nodejs; press enter for every prompt. - type
npm install express --saveto set the express module as a dependency - Add a file named index.js and paste this code:
var express = require('express');
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
// views is directory for all template files
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.get('/', function(request, response) {
response.render('pages/index');
});
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});
- Add a folder named 'public' and add 'index.html' inside the public folder.
- Push these additions to the github server with:
git add > git commit > git push origin master
You've just created a node server. It differs slightly from the tutorial in header 1 but the basis is the same. Using express, you will be serving your website from the public folder where you can add other html pages there, and create front-end scripts here. You may also make changes to index.js and create RESTful routes which will be in another tutorial. As a final note. in step 3. 'index.js' is usually renamed as 'server.js'.
#6 Deploying Heroku Web Server
- In the command shell/line, type
heroku create - Type
git push heroku master - View your website with
heroku open
Any time you make changes to your web server, you will need to push it to github, and heroku. you will be using git push and git push heroku master to keep your webserver updated.