8000 Initial commit by manishas · Pull Request #1 · devops-recipes/basic-node · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,27 @@
# basic-node
This is a basic Node.js project which displays the Shippable Aye Aye.

# Continuous Integration for a Node JS application
[![Run Status](https://api.shippable.com/projects/588579c63b653a0f00fa68d3/badge?branch=master)](https://app.shippable.com/projects/588579c63b653a0f00fa68d3)
[![Coverage Badge](https://api.shippable.com/projects/588579c63b653a0f00fa68d3/coverageBadge?branch=master)](https://app.shippable.com/projects/588579c63b653a0f00fa68d3)

A simple Node JS application with unit tests and coverage reports using mocha
and istanbul.

![AyeAye](https://github.com/shippableSamples/node-with-tests-coverage/blob/master/public/resources/images/captain.png)

## Run CI for this repo on Shippable
* Fork this repo into your local repo
* Login into the [Continuous Integration Service](wwww.shippable.com)
* All CI configuration is in `shippable.yml`
* Follow these [CI Setup Instructions](http://docs.shippable.com/ci/runFirstBuild/) if you have never used Shippable CI Service
* You should be able to run a manual build or webhook build on commit

## CI Reports on Shippable

### CI Console Output
![CI Console Output](https://github.com/shippableSamples/node-with-tests-coverage/blob/master/public/resources/images/console.jpg)

### CI Test Report
![CI Test Report](https://github.com/shippableSamples/node-with-tests-coverage/blob/master/public/resources/images/tests.jpg)

### CI Coverage Report
![CI Coverage Report](https://github.com/shippableSamples/node-with-tests-coverage/blob/master/public/resources/images/coverage.jpg)
76 changes: 76 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');
var name = require('./routes/name');
var properties = require('./routes/properties');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.get("/public/*",
function (req, res) {
res.sendFile(__dirname + req.originalUrl);
}
);

// uncomment after placing your favicon in /public
app.use(favicon(path.join(__dirname, 'public/resources/images', 'nodejs.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', routes);
app.use('/users', users);
app.use('/name', name);
app.use('/properties', properties);

// catch 404 and forward to error handler
app.use(
function (req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
}
);

// error handlers

// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(
function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: err
}
);
}
);
}

// production error handler
// no stacktraces leaked to user
app.use(
function (err, req, res, next) {
res.status(err.status || 500);
res.render('error', {
message: err.message,
error: {}
}
);
}
);

module.exports = app;
90 changes: 90 additions & 0 deletions bin/www
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/usr/bin/env node

/**
* Module dependencies.
*/

var app = require('../app');
var debug = require('debug')('vb-docker-app:server');
var http = require('http');

/**
* Get port from environment and store in Express.
*/

var port = normalizePort(process.env.PORT);
app.set('port', port);

/**
* Create HTTP server.
*/

var server = http.createServer(app);

/**
* Listen on provided port, on all network interfaces.
*/

server.listen(port);
server.on('error', onError);
server.on('listening', onListening);

/**
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
var port = parseInt(val, 10);

if (isNaN(port)) {
// named pipe
return val;
}

if (port >= 0) {
// port number
return port;
}

return false;
}

/**
* Event listener for HTTP server "error" event.
*/

function onError(error) {
if (error.syscall !== 'listen') {
throw error;
}

var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port;

// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges');
process.exit(1);
break;
case 'EADDRINUSE':
console.error(bind + ' is already in use');
process.exit(1);
break;
default:
throw error;
}
}

/**
* Event listener for HTTP server "listening" event.
*/

function onListening() {
var addr = server.address();
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port;
debug('Listening on ' + bind);
}
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "node-with-tests-coverage",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.13.2",
"cookie-parser": "~1.3.5",
"debug": "~2.2.0",
"ejs": "~2.3.3",
"express": "~4.13.1",
"ip": "^1.1.4",
"istanbul": "^0.4.5",
"mocha": "^3.2.0",
"mocha-junit-reporter": "^1.13.0",
"morgan": "~1.6.1",
"serve-favicon": "~2.3.0",
"spec-xunit-file": "0.0.1-3",
"supertest": "^2.0.1"
}
}
34 changes: 34 additions & 0 deletions public/resources/css/app.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
body {
padding-top: 50px;
background-color: #118456;
}

.starter-template {
padding: 40px 15px;
text-align: center;
}

.bs-docs-masthead {
padding: 80px 0;
}

.bs-docs-header, .bs-docs-masthead {
position: relative;
padding: 30px 0;
color: #fff;
text-align: center;
text-shadow: 0 1px 0 rgba(0, 0, 0, .1);
background-color: #328A2E;
background-image: -webkit-gradient(linear, left top, left bottom, from(#09AE5C), to(#09AE5C));
background-image: -webkit-linear-gradient(top, #09AE5C 0, #09AE5C 100%);
background-image: -o-linear-gradient(top, #09AE5C 0, #09AE5C 100%);
background-image: linear-gradient(to bottom, #09AE5C 0, #2E608A 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#09AE5C', endColorstr='#09AE5C', GradientType=0);
background-repeat: repeat-x;
}

.name-form {
margin: 10px;
}

@media (min-width: 768px){}
Loading
0