Code Challenge - 2) More Baseline

Working and Needs Improvement

Got the thing wired top to bottom, and need a heavy refactor to hit all the requirement firmly.

finished work

Note to Self: Sass flag!

Dammit, man! I shoulda used the Sass flag.

Step 1) Add and Wire Express

Install Express

Get the basics in place.

npm install --save express

Create www in /bin/

Create a www file for the Express details (like ports, etc) in a /bin/ directory.

I pulled these ~95 lines from a scaffolded project and updated the debug var, giving it the proper name.

var debug = require('debug')('nodeaction:server');

Check the repo for the full code.

Create app.js

Add a simple app.js as our entry point for the Express side of the equation.

Set up handling for 404, 500, and routing.

(Final code after I fix a bug below.)

Create Basic Routing

Create routes/index.js and add a very simple response.

let express = require('express');  
let router = express.Router();

// ship something back to show it works
router.get('/', (req, res, next) => {  
  res.send('Express working.')

module.exports = router;  

Update Scripts

Update the start scripts in package.json, point to the www file.

"start": "ng serve",
"serve": "node ./src/bin/www",

Working. Kinda.

Working - kinda - 004

I got a 404 error after taking a look.

Add a Rendering Engine

...because I missed adding a rendering engine. So, add body-parser:

npm install --save body-parser


// use bodyParser for the rendering engine
app.use(bodyParser.urlencoded({'extended': 'false'}));  

No errors now.

Both Angular 4 — via ng serve — and Express — via node ./src — can run at the same time.

Not sure that's ideal though it works.


Now looks like this:

let express    = require('express');  
let bodyParser = require('body-parser');

let index = require('./routes/index');

let app = express();

// use bodyParser for the rendering engine
app.use(bodyParser.urlencoded({'extended': 'false'}));

// routing
app.use('/', index);

// catch 404
app.use((req, res, next) => {  
  let err    = new Error('Not found.');
  err.status = 404;

// error handler
app.use((err, req, res, next) => {

  // set locals for dev environment (via scaffold from another project)
  res.locals.message = err.message;
  res.locals.error   ='env') === 'development' ? err : {};

  res.status(err.status || 500);


module.exports = app;  

Pretty lean.

Commit & Push, Eat Lunch & Mind Break

Get the code out to GitHub, and get some fuel for me.

Study Neo4j

Watched about 4 hours of vids, taking copious notes. First notes over here.

Installed Neo4j Community Edition on the Mac, and got to Hello World.

This is both new and intuitive.

Stub Docker

Will come back to this after getting the thing wired, however I threw in a basic setup.

Again, waaaaay more to come.