Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
students
git example
Commits
278f5d67
Commit
278f5d67
authored
Jan 13, 2023
by
Park Sungwoo
Browse files
123
parent
16b2e59a
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/app.js
View file @
278f5d67
import
express
from
"
express
"
;
import
express
from
"
express
"
;
import
User
from
"
./models/usesrs.models
"
const
port
=
3000
;
const
port
=
3000
;
const
app
=
express
();
const
app
=
express
();
app
.
get
(
"
/
"
,
(
req
,
res
)
=>
{
app
.
get
(
"
/
"
,
(
req
,
res
)
=>
{
console
.
log
(
"
root path get method called.
"
)
console
.
log
(
"
root path get method called.
"
)
;
res
.
send
(
"
!23
"
)
res
.
send
(
"
<h1> 안녕하세요. </h1>
"
)
;
})
})
app
.
get
(
"
/users
"
,
async
(
req
,
res
)
=>
{
app
.
listen
(
port
,
()
=>
{
User
.
create
({
password
:
"
xxx
"
,
email
:
"
xxx@example.com
"
,
name
:
"
dkxkdkf
"
});
console
.
log
(
`server is runnug at
${
port
}
port.`
)
console
.
log
(
"
new user:
"
,
newUser
);
const
users
=
await
User
.
find
();
res
.
json
(
users
);
})
})
// app.listen(port, () => {
// console.log(`server is runnug at ${port} port.`)
// })
export
default
app
export
default
app
\ No newline at end of file
src/models/users.model.js
0 → 100644
View file @
278f5d67
import
mongoose
from
"
mongoose
"
;
const
validateEmail
=
(
email
=>
{
const
re
=
/^
\w
+
([\,
-
]?\w
+
)
*@
\w
+
([\,
-
]?\w
+
)
*
(\.\w{2,3})
+$/
;
return
re
.
test
(
email
)
})
const
schema
=
new
mongoose
.
Schema
({
email
:{
type
:
String
,
rquired
:
true
,
unique
:
true
,
validate
:
[
validateEmail
,
"
이메일을 입력해주세요.
"
],
},
name
:
{
type
:
string
},
password
:
{
type
:
string
,
required
:
true
,
select
:
false
},
role
:{
type
:
schema
.
types
.
objectId
,
ref
:
"
Role
"
},
}
);
export
default
schema
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment