You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 );
} );