A basic deployable web app.
You want to make a web app but you don't know where to start.
- Write your client code in HTML, Javascript, CSS in pageview.html.
- Write your webserver code in index.js (for NodeJS).
View the webapp here: Software Engineering Web Technology
- Node & NPM: https://nodejs.org/en/download/
- Heroku CLI: https://devcenter.heroku.com/articles/heroku-cli
- Heroku Account: https://signup.heroku.com/
- Git: https://git-scm.com/downloads
- Github Account: https://github.com/join
git clone https://github.com/luisschubert/basicwebapp.git && cd basicwebapp && npm install && npm start
heroku create && git push heroku master && heroku open
The html file which contains the structure of the elements that comprise the view represented in the browser.
The node.js file that contains the webserver.
const express = require('express');
const fs = require('fs');
const app = express();
app.set('port', (process.env.PORT || 7777));
// this creates a route for "/"
// the route responds to a HTTP request with an HTTP response
// the function that gets called for the / route
// (req, res) => {
//
// }
// (req, res) are the arguments to a function
// => denotes that the following block is the body of the function
// {} the block where the code for the function resides
app.get('/', (req, res) => {
// read pageview.html from the os
fs.readFile('pageview.html', (err, data) => {
// check to see if the html file was loaded with an error
if(err) {
// if an error occurs return a 500 error
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500
res.statusCode = 500;
}
else {
// set the header to the content html file being served
res.setHeader('Content-type','text/html');
// write the content of the html file to HTTP Response
res.end(data);
}
})
});
// set the port number of the webserver for listening to HTTP Requests
app.listen(app.get('port'), () => {
console.log(`Node.js server is running`);
console.log(`Listening for clients on port ${app.get('port')}`);
console.log('http://localhost:7777');
console.log('http://127.0.0.1:7777');
})
The npm file which is used for the npm package manager.
Specifies heroku configuration.
The heroku app file.
For your web server code you could be using many different programming languages. Amongst the most common are:
- PHP
- Python
- NodeJS
- Java
- Scala
- Ruby
- Clojure
- Go
- .Net