Skip to content

Commit 2660b73

Browse files
committed
initialize project
0 parents  commit 2660b73

File tree

14 files changed

+1196
-0
lines changed

14 files changed

+1196
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# cicd-pipeline-train-schedule-git
2+
3+
This is a simple train schedule app written using nodejs. It is intended to be used as a sample application for a series of hands-on learning activities.
4+
5+
## Running the app
6+
7+
It is not necessary to run this app locally in order to complete the learning activities, but if you wish to do so you will need a local installation of npm. Begin by installing the npm dependencies with:
8+
9+
npm install
10+
11+
Then, you can run the app with:
12+
13+
npm start
14+
15+
Once it is running, you can access it in a browser at [http://localhost:3000](http://localhost:3000)

app.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var createError = require('http-errors');
2+
var express = require('express');
3+
var path = require('path');
4+
var cookieParser = require('cookie-parser');
5+
var logger = require('morgan');
6+
7+
var indexRouter = require('./routes/index');
8+
var trainsRouter = require('./routes/trains');
9+
10+
var app = express();
11+
12+
// view engine setup
13+
app.set('views', path.join(__dirname, 'views'));
14+
app.set('view engine', 'jade');
15+
16+
app.use(logger('dev'));
17+
app.use(express.json());
18+
app.use(express.urlencoded({ extended: false }));
19+
app.use(cookieParser());
20+
app.use(express.static(path.join(__dirname, 'public')));
21+
22+
app.use('/', indexRouter);
23+
app.use('/trains', trainsRouter);
24+
25+
// catch 404 and forward to error handler
26+
app.use(function(req, res, next) {
27+
next(createError(404));
28+
});
29+
30+
// error handler
31+
app.use(function(err, req, res, next) {
32+
// set locals, only providing error in development
33+
res.locals.message = err.message;
34+
res.locals.error = req.app.get('env') === 'development' ? err : {};
35+
36+
// render the error page
37+
res.status(err.status || 500);
38+
res.render('error');
39+
});
40+
41+
module.exports = app;

bin/www

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var app = require('../app');
8+
var debug = require('debug')('cicd-pipeline-train-schedule-git:server');
9+
var http = require('http');
10+
11+
/**
12+
* Get port from environment and store in Express.
13+
*/
14+
15+
var port = normalizePort(process.env.PORT || '3000');
16+
app.set('port', port);
17+
18+
/**
19+
* Create HTTP server.
20+
*/
21+
22+
var server = http.createServer(app);
23+
24+
/**
25+
* Listen on provided port, on all network interfaces.
26+
*/
27+
28+
server.listen(port);
29+
server.on('error', onError);
30+
server.on('listening', onListening);
31+
32+
/**
33+
* Normalize a port into a number, string, or false.
34+
*/
35+
36+
function normalizePort(val) {
37+
var port = parseInt(val, 10);
38+
39+
if (isNaN(port)) {
40+
// named pipe
41+
return val;
42+
}
43+
44+
if (port >= 0) {
45+
// port number
46+
return port;
47+
}
48+
49+
return false;
50+
}
51+
52+
/**
53+
* Event listener for HTTP server "error" event.
54+
*/
55+
56+
function onError(error) {
57+
if (error.syscall !== 'listen') {
58+
throw error;
59+
}
60+
61+
var bind = typeof port === 'string'
62+
? 'Pipe ' + port
63+
: 'Port ' + port;
64+
65+
// handle specific listen errors with friendly messages
66+
switch (error.code) {
67+
case 'EACCES':
68+
console.error(bind + ' requires elevated privileges');
69+
process.exit(1);
70+
break;
71+
case 'EADDRINUSE':
72+
console.error(bind + ' is already in use');
73+
process.exit(1);
74+
break;
75+
default:
76+
throw error;
77+
}
78+
}
79+
80+
/**
81+
* Event listener for HTTP server "listening" event.
82+
*/
83+
84+
function onListening() {
85+
var addr = server.address();
86+
var bind = typeof addr === 'string'
87+
? 'pipe ' + addr
88+
: 'port ' + addr.port;
89+
debug('Listening on ' + bind);
90+
}

data/trains.json

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"trains": [
3+
{
4+
"name": "Hogwarts Express",
5+
"stops": [
6+
{
7+
"station": "Sycamore",
8+
"status": "ON-TIME",
9+
"arrival": "12:00pm",
10+
"departure": "12:10pm"
11+
},
12+
{
13+
"station": "Pine",
14+
"status": "ON-TIME",
15+
"arrival": "1:00pm",
16+
"departure": "1:10pm"
17+
}
18+
]
19+
},
20+
{
21+
"name": "Flying Scotsman",
22+
"stops": [
23+
{
24+
"station": "Pine",
25+
"status": "ON-TIME",
26+
"arrival": "12:00pm",
27+
"departure": "12:10pm"
28+
},
29+
{
30+
"station": "Sycamore",
31+
"status": "DELAYED",
32+
"arrival": "1:00pm",
33+
"departure": "1:10pm",
34+
"delayedArrival": "1:00pm",
35+
"delayedDeparture": "1:17pm"
36+
}
37+
]
38+
},
39+
{
40+
"name": "Orient Express",
41+
"stops": [
42+
{
43+
"station": "Sycamore",
44+
"status": "ON-TIME",
45+
"arrival": "12:00pm",
46+
"departure": "12:10pm"
47+
},
48+
{
49+
"station": "Cypress",
50+
"status": "DELAYED",
51+
"arrival": "1:00pm",
52+
"departure": "1:10pm",
53+
"delayedArrival": "1:07pm",
54+
"delayedDeparture": "1:17pm"
55+
}
56+
]
57+
},
58+
{
59+
"name": "Golden Arrow",
60+
"stops": [
61+
{
62+
"station": "Cypress",
63+
"status": "ON-TIME",
64+
"arrival": "12:00pm",
65+
"departure": "12:10pm"
66+
},
67+
{
68+
"station": "Pine",
69+
"status": "DELAYED",
70+
"arrival": "1:00pm",
71+
"departure": "1:10pm",
72+
"delayedArrival": "1:07pm",
73+
"delayedDeparture": "1:17pm"
74+
},
75+
{
76+
"station": "Hickory",
77+
"status": "DELAYED",
78+
"arrival": "1:00pm",
79+
"departure": "1:10pm",
80+
"delayedArrival": "1:07pm",
81+
"delayedDeparture": "1:17pm"
82+
}
83+
]
84+
}
85+
]
86+
}

0 commit comments

Comments
 (0)