FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Nodejs-REST-API/app.js at master · chavan-arvind/Nodejs-REST-API · GitHub
chavan-arvind
/
Nodejs-REST-API
Public
forked from
trulymittal/Nodejs-REST-API
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Nodejs-REST-API
/
app.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (34 loc) · 938 Bytes
Breadcrumbs
Nodejs-REST-API
/
app.js
Copy path
File metadata and controls
42 lines (34 loc) · 938 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const
express
=
require
(
'express'
)
;
const
createError
=
require
(
'http-errors'
)
;
const
dotenv
=
require
(
'dotenv'
)
.
config
(
)
;
const
app
=
express
(
)
;
app
.
use
(
express
.
json
(
)
)
;
app
.
use
(
express
.
urlencoded
(
{
extended
:
true
}
)
)
;
// Initialize DB
require
(
'./initDB'
)
(
)
;
const
ProductRoute
=
require
(
'./Routes/Product.route'
)
;
app
.
use
(
'/products'
,
ProductRoute
)
;
//404 handler and pass to error handler
app
.
use
(
(
req
,
res
,
next
)
=>
{
/*
const err = new Error('Not found');
err.status = 404;
next(err);
*/
// You can use the above code if your not using the http-errors module
next
(
createError
(
404
,
'Not found'
)
)
;
}
)
;
//Error handler
app
.
use
(
(
err
,
req
,
res
,
next
)
=>
{
res
.
status
(
err
.
status
||
500
)
;
res
.
send
(
{
error
:
{
status
:
err
.
status
||
500
,
message
:
err
.
message
}
}
)
;
}
)
;
const
PORT
=
process
.
env
.
PORT
||
3000
;
app
.
listen
(
PORT
,
(
)
=>
{
console
.
log
(
'Server started on port '
+
PORT
+
'...'
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL