Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

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
You can’t perform that action at this time.