Skip to content

Instantly share code, notes, and snippets.

@goofballLogic
Last active May 17, 2018 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goofballLogic/483bf02c8f226f306fa9c306faa24916 to your computer and use it in GitHub Desktop.
Save goofballLogic/483bf02c8f226f306fa9c306faa24916 to your computer and use it in GitHub Desktop.

Create a folder named "routes", and one named "middleware"

api
   middleware                        <---
   node_modules
   routes                            <---
   .gitignore
   index.js
   package-lock.json
   package.json

Create a hello-route module and move the hello code into it

function configure( app ) {

    // configure the hello Andrew route
    app.get( "/", function( req, res ) {

        res.send( { "message": "hello " + req.query.name } );

    } );

}

module.exports = { configure };

Use this module from index.js

var express = require("express");
var app = express();

var helloRoute = require( "./routes/helloRoute" );
helloRoute.configure( app );

// listen
var PORT = process.env.PORT || 3000;
app.listen( PORT, function() {

	console.log( "Listening on port " + PORT );

} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment