Skip to content

Commit bc3f63b

Browse files
author
Alistair Prestidge
committed
Initial commit of test
0 parents  commit bc3f63b

File tree

12 files changed

+3069
-0
lines changed

12 files changed

+3069
-0
lines changed

Diff for: .gitignore

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
10+
# Diagnostic reports (https://nodejs.org/api/report.html)
11+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12+
13+
# Runtime data
14+
pids
15+
*.pid
16+
*.seed
17+
*.pid.lock
18+
19+
# Directory for instrumented libs generated by jscoverage/JSCover
20+
lib-cov
21+
22+
# Coverage directory used by tools like istanbul
23+
coverage
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# Optional npm cache directory
48+
.npm
49+
50+
# Optional eslint cache
51+
.eslintcache
52+
53+
# Optional REPL history
54+
.node_repl_history
55+
56+
# Output of 'npm pack'
57+
*.tgz
58+
59+
# Yarn Integrity file
60+
.yarn-integrity
61+
62+
# dotenv environment variables file
63+
.env
64+
.env.test
65+
66+
# parcel-bundler cache (https://parceljs.org/)
67+
.cache
68+
69+
# next.js build output
70+
.next
71+
72+
# nuxt.js build output
73+
.nuxt
74+
75+
# vuepress build output
76+
.vuepress/dist
77+
78+
# Serverless directories
79+
.serverless/
80+
81+
# FuseBox cache
82+
.fusebox/
83+
84+
# DynamoDB Local files
85+
.dynamodb/

Diff for: 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 helloRouter = require('./routes/helloworld');
9+
10+
var app = express();
11+
12+
// view engine setup
13+
app.set('views', path.join(__dirname, 'views'));
14+
app.set('view engine', 'pug');
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('/hello-world', helloRouter);
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;

Diff for: 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')('candidateassignment-nodejs: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+
}

0 commit comments

Comments
 (0)