Guest User

Untitled

a guest
May 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. # Create a folder named "routes", and one named "middleware"
  2.  
  3. ```
  4. api
  5. middleware <---
  6. node_modules
  7. routes <---
  8. .gitignore
  9. index.js
  10. package-lock.json
  11. package.json
  12. ```
  13.  
  14. # Create a hello-route module and move the hello code into it
  15.  
  16. ```
  17. function configure( app ) {
  18.  
  19. // configure the hello Andrew route
  20. app.get( "/", function( req, res ) {
  21.  
  22. res.send( { "message": "hello " + req.query.name } );
  23.  
  24. } );
  25.  
  26. }
  27.  
  28. module.exports = { configure };
  29. ```
  30.  
  31. # Use this module from index.js
  32.  
  33. ```
  34. var express = require("express");
  35. var app = express();
  36.  
  37. var helloRoute = require( "./routes/helloRoute" );
  38. helloRoute.configure( app );
  39.  
  40. // listen
  41. var PORT = process.env.PORT || 3000;
  42. app.listen( PORT, function() {
  43.  
  44. console.log( "Listening on port " + PORT );
  45.  
  46. } );
  47. ```
Add Comment
Please, Sign In to add comment