Commit 192ab3f sourabh
committed
1 parent 70b2da0 commit 192ab3f Copy full SHA for 192ab3f
File tree 6 files changed +43
-1
lines changed
6 files changed +43
-1
lines changed Original file line number Diff line number Diff line change
1
+ PORT = 4000
Original file line number Diff line number Diff line change
1
+ require ( "dotenv" ) . config ( ) ;
2
+ const express = require ( 'express' )
3
+ const app = express ( )
4
+
5
+ // Ref: ✈️🔗https://expressjs.com/en/5x/api.html#router
6
+
7
+ // BRINGS ROUTES
8
+ const home = require ( "./routes/home" ) ;
9
+
10
+ // USING MIDDLEWARE
11
+ app . use ( "/api/v1" , home ) ;
12
+
13
+ module . exports = app ;
Original file line number Diff line number Diff line change
1
+ exports . home = ( req , res ) => {
2
+ res . status ( 200 ) . json ( {
3
+ success :true ,
4
+ gretting :"Hello,Home Page From API"
5
+ } )
6
+ }
7
+ exports . Dummy = ( req , res ) => {
8
+ res . status ( 200 ) . json ( {
9
+ success :true ,
10
+ gretting :"Hello,Dummy From API"
11
+ } )
12
+ }
Original file line number Diff line number Diff line change
1
+ require ( "dotenv" ) . config ( ) ;
2
+ const app = require ( "./app" )
3
+
4
+ app . listen ( process . env . PORT , ( ) => {
5
+ console . log ( `Example app listening on port http://localhost:${ process . env . PORT } /api/v1` )
6
+ } )
Original file line number Diff line number Diff line change 4
4
"description" : " a backend api for tshirt store" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
7
- "test" : " echo \" Error: no test specified\" && exit 1"
7
+ "start" : " nodemon index.js" ,
8
+ "dev" : " node index.js"
8
9
},
9
10
"keywords" : [
10
11
" api" ,
Original file line number Diff line number Diff line change
1
+ const express = require ( 'express' ) ;
2
+ const { home, Dummy } = require ( '../controllers/home' ) ;
3
+ const router = express . Router ( ) ;
4
+
5
+ // router.get("/",home)
6
+ router . route ( "/" ) . get ( home )
7
+ router . route ( "/d" ) . get ( Dummy )
8
+
9
+ module . exports = router ;
You can’t perform that action at this time.
0 commit comments