File tree 1 file changed +36
-0
lines changed
1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ const express = require ( "express" ) ;
2
+ const app = express ( ) ;
3
+ const PORT = 3000 ;
4
+
5
+ const arrowFunction = ( req , res , next ) => {
6
+ console . log ( "I am an arrow function!" ) ;
7
+ next ( ) ;
8
+ } ;
9
+
10
+ app . use ( arrowFunction ) ;
11
+
12
+ const checkColor = ( ) => {
13
+ return ( req , res , next ) => {
14
+ if ( req . query . color ) {
15
+ res . send ( "I have blue!" ) ;
16
+ } else {
17
+ next ( ) ;
18
+ }
19
+ } ;
20
+ } ;
21
+
22
+ app . use ( checkColor ( ) ) ;
23
+
24
+ app . get ( "/users" , function ( req , res ) {
25
+ console . log ( "users list was shown" ) ;
26
+ res . send ( "Here is a list of users:...." ) ;
27
+ } ) ;
28
+
29
+ app . get ( "/books" , function ( req , res ) {
30
+ console . log ( "books list was shown" ) ;
31
+ res . send ( "Here is a list of books:...." ) ;
32
+ } ) ;
33
+
34
+ const server = app . listen ( PORT , ( ) => {
35
+ console . log ( `Server running at http://localhost:${ PORT } ` ) ;
36
+ } ) ;
You can’t perform that action at this time.
0 commit comments