Skip to content

Instantly share code, notes, and snippets.

@natmegs natmegs/app.js
Last active Aug 26, 2017

What would you like to do?
Second express example, separating routes into different controller files
var express = require('express');
var app = express();
// Import the functions returned by apiController and htmlController
// to add endpoints/routes to app.
var apiController = require('./controllers/apiController');
var htmlController = require('./controllers/htmlController');
var port = process.env.PORT || 3000;
// Middleware
app.use('/assets', express.static(__dirname + '/public'));
app.use('/', function(req, res, next){
console.log('Request Url: ' + req.url);
// Routes
// Can pass app around since it is an object (mutable/passed by ref).
// Pass our app to the function returned by
// apiController, which adds /api endpoints to app.
// Same with html controller.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.