Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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 );
- } );
- ```
Add Comment
Please, Sign In to add comment