├── .gitignore ├── public ├── favicon.ico ├── favicon.png ├── css │ └── style.css └── images │ └── loading.svg ├── routes ├── index.js └── contact.js ├── README.md ├── package.json ├── views ├── error.html └── index.html ├── app.js └── bin └── www /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afj176/ng5-express-starter/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afj176/ng5-express-starter/HEAD/public/favicon.png -------------------------------------------------------------------------------- /routes/index.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET home page. */ 5 | router.get('/', function(req, res, next) { 6 | res.render('index.html', { title: 'Angular 5 / Express Starter' }); 7 | }); 8 | 9 | module.exports = router; 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ### About 2 | 3 | Borrows from https://embed.plnkr.co/4Ddi0C/ 4 | 5 | ### Instructions 6 | 7 | install dependencies: 8 | 9 | ```bash 10 | npm install 11 | ``` 12 | 13 | run the app: 14 | 15 | ```bash 16 | npm start 17 | ``` 18 | 19 | preview app: 20 | 21 | ``` 22 | http://localhost:3000/ 23 | ``` 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng2-express-starter", 3 | "version": "0.1.1", 4 | "private": true, 5 | "scripts": { 6 | "start": "node ./bin/www" 7 | }, 8 | "dependencies": { 9 | "body-parser": "^1.18.2", 10 | "cookie-parser": "^1.4.3", 11 | "debug": "^3.1.0", 12 | "ejs": "^2.5.7", 13 | "express": "^4.16.2", 14 | "morgan": "^1.9.0", 15 | "serve-favicon": "^2.4.5" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /routes/contact.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var router = express.Router(); 3 | 4 | /* GET users listing. */ 5 | router.post('/', function(req, res, next) { 6 | if(typeof req.body.message !== 'undefined'){ 7 | res.status(200).json({'message': 'Thank you for reaching out!'}); 8 | }else{ 9 | res.status(500).json({'message': 'Please add a message.'}); 10 | } 11 | }); 12 | 13 | module.exports = router; 14 | -------------------------------------------------------------------------------- /public/css/style.css: -------------------------------------------------------------------------------- 1 | html{position:relative;} 2 | html,body{min-height:100%;height:100%;} 3 | body{margin:0;padding:0;} 4 | stage{display:block;} 5 | stage:focus,.stage:focus{outline:none;} 6 | stage,.stage{display:block;max-width:600px;margin:40px auto 10px;position:relative;} 7 | body > .site-name{display:block; max-width:500px; margin: 40px auto 10px; position:relative; text-align:center;} 8 | body > .lead{max-width:500px;margin:0 auto;display:block;position:relative; text-align: center;} 9 | .loading{display:block;width:94px;margin:50px auto;} 10 | .contact,.display{margin:20px 0;} 11 | -------------------------------------------------------------------------------- /views/error.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%= title %> 8 | 9 | 10 | 11 | 12 |

<%= title %>

13 |
14 |

<%= error.status %> : <%= message %>

15 |
<%= error.stack %>
16 |
17 | 18 | -------------------------------------------------------------------------------- /views/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%= title %> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 |

<%= title %>

23 |

Uses UNPKG & SystemJS to quickly boostrap an Angular App

24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var path = require('path'); 3 | var favicon = require('serve-favicon'); 4 | var logger = require('morgan'); 5 | var cookieParser = require('cookie-parser'); 6 | var bodyParser = require('body-parser'); 7 | 8 | var routes = require('./routes/index'); 9 | var contact = require('./routes/contact'); 10 | 11 | var app = express(); 12 | 13 | // view engine setup 14 | app.set('views', path.join(__dirname, 'views')); 15 | app.set('view engine', 'ejs'); 16 | app.engine('html', require('ejs').renderFile); 17 | app.use(favicon(__dirname + '/public/favicon.ico')); 18 | app.use(logger('dev')); 19 | app.use(bodyParser.json()); 20 | app.use(bodyParser.urlencoded({ extended: false })); 21 | app.use(cookieParser()); 22 | app.use(express.static(path.join(__dirname, 'public'))); 23 | 24 | app.use('/', routes); 25 | app.use('/contact', contact); 26 | 27 | // catch 404 and forward to error handler 28 | app.use(function(req, res, next) { 29 | var err = new Error('Not Found'); 30 | err.status = 404; 31 | next(err); 32 | }); 33 | 34 | // error handlers 35 | 36 | // development error handler 37 | // will print stacktrace 38 | if (app.get('env') === 'development') { 39 | app.use(function(err, req, res, next) { 40 | res.status(err.status || 500); 41 | res.render('error.html', { 42 | title: 'ng2 Express Starter', 43 | message: err.message, 44 | error: err 45 | }); 46 | }); 47 | } 48 | 49 | // production error handler 50 | // no stacktraces leaked to user 51 | app.use(function(err, req, res, next) { 52 | res.status(err.status || 500); 53 | res.render('error.html', { 54 | title: 'ng2 Express Starter', 55 | message: err.message, 56 | error: {} 57 | }); 58 | }); 59 | 60 | 61 | module.exports = app; 62 | -------------------------------------------------------------------------------- /bin/www: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * Module dependencies. 5 | */ 6 | 7 | var app = require('../app'); 8 | var debug = require('debug')('ng2-express-starter: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 | } 91 | -------------------------------------------------------------------------------- /public/images/loading.svg: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------