FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
api-project-sample1/app.js at master · behzadCode/api-project-sample1 · GitHub
behzadCode
/
api-project-sample1
Public
forked from
maitraysuthar/rest-api-nodejs-mongodb
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
api-project-sample1
/
app.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
57 lines (49 loc) · 1.54 KB
Breadcrumbs
api-project-sample1
/
app.js
Copy path
File metadata and controls
57 lines (49 loc) · 1.54 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var
express
=
require
(
"express"
)
;
var
path
=
require
(
"path"
)
;
var
cookieParser
=
require
(
"cookie-parser"
)
;
var
logger
=
require
(
"morgan"
)
;
require
(
"dotenv"
)
.
config
(
)
;
var
indexRouter
=
require
(
"./routes/index"
)
;
var
apiRouter
=
require
(
"./routes/api"
)
;
var
apiResponse
=
require
(
"./helpers/apiResponse"
)
;
var
cors
=
require
(
"cors"
)
;
// DB connection
var
MONGODB_URL
=
process
.
env
.
MONGODB_URL
;
var
mongoose
=
require
(
"mongoose"
)
;
mongoose
.
connect
(
MONGODB_URL
,
{
useNewUrlParser
:
true
,
useUnifiedTopology
:
true
}
)
.
then
(
(
)
=>
{
//don't show the log when it is test
if
(
process
.
env
.
NODE_ENV
!==
"test"
)
{
console
.
log
(
"Connected to %s"
,
MONGODB_URL
)
;
console
.
log
(
"App is running ... \n"
)
;
console
.
log
(
"Press CTRL + C to stop the process. \n"
)
;
}
}
)
.
catch
(
err
=>
{
console
.
error
(
"App starting error:"
,
err
.
message
)
;
process
.
exit
(
1
)
;
}
)
;
var
db
=
mongoose
.
connection
;
var
app
=
express
(
)
;
//don't show the log when it is test
if
(
process
.
env
.
NODE_ENV
!==
"test"
)
{
app
.
use
(
logger
(
"dev"
)
)
;
}
app
.
use
(
express
.
json
(
)
)
;
app
.
use
(
express
.
urlencoded
(
{
extended
:
false
}
)
)
;
app
.
use
(
cookieParser
(
)
)
;
app
.
use
(
express
.
static
(
path
.
join
(
__dirname
,
"public"
)
)
)
;
//To allow cross-origin requests
app
.
use
(
cors
(
)
)
;
//Route Prefixes
app
.
use
(
"/"
,
indexRouter
)
;
app
.
use
(
"/api/"
,
apiRouter
)
;
// throw 404 if URL not found
app
.
all
(
"*"
,
function
(
req
,
res
)
{
return
apiResponse
.
notFoundResponse
(
res
,
"Page not found"
)
;
}
)
;
app
.
use
(
(
err
,
req
,
res
)
=>
{
if
(
err
.
name
==
"UnauthorizedError"
)
{
return
apiResponse
.
unauthorizedResponse
(
res
,
err
.
message
)
;
}
}
)
;
module
.
exports
=
app
;
Back
|
FazBrowse Home
|
New Git URL