Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
N
nodejs-60-2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
winai buttasart
nodejs-60-2
Commits
a8bb0973
Commit
a8bb0973
authored
Feb 07, 2018
by
winai buttasart
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add contact-manager CLI project
parent
238ca4dc
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
156 additions
and
0 deletions
+156
-0
.gitignore
.gitignore
+2
-0
index.js
week04/contact-manager/index.js
+45
-0
logic.js
week04/contact-manager/logic.js
+75
-0
note in class.txt
week04/contact-manager/note in class.txt
+19
-0
package.json
week04/contact-manager/package.json
+15
-0
No files found.
.gitignore
0 → 100644
View file @
a8bb0973
node_modules/
\ No newline at end of file
week04/contact-manager/index.js
0 → 100644
View file @
a8bb0973
const
program
=
require
(
'commander'
);
const
{
addContact
,
getContact
}
=
require
(
'./logic'
);
// const a = require('./logic');
// console.log(a.toLower("winaiWWERWER"));
// Require logic.js file and extract controller functions using JS destructuring assignment
program
.
version
(
'0.1.0'
)
.
description
(
'Contact management system'
);
program
.
command
(
'addContact <firstame> <lname> <phone> <email>'
)
.
alias
(
'a'
)
.
description
(
'Add a contact'
)
.
action
((
fname
,
lname
,
phone
,
email
)
=>
{
// console.log(`User : ${fname} ${lname} ${phone} ${email}`);
addContact
({
fname
,
lname
,
phone
,
email
});
});
program
.
command
(
'getContact <name>'
)
.
alias
(
'r'
)
.
description
(
'Get contact'
)
.
action
(
name
=>
getContact
(
name
));
program
.
command
(
'programmer'
)
.
alias
(
'p'
)
.
description
(
'ดูข้อมูลโปรแกรมเมอร์'
)
.
action
(()
=>
{
console
.
log
(
'Programmer คือ วินัย'
);
});
program
.
parse
(
process
.
argv
);
\ No newline at end of file
week04/contact-manager/logic.js
0 → 100644
View file @
a8bb0973
const
mongoose
=
require
(
'mongoose'
);
// const assert = require('assert');
mongoose
.
Promise
=
global
.
Promise
;
//old mongoose connect
// const db = mongoose.connect('mongodb://localhost:27017/contactdb');
//new mongoose connect
mongoose
.
connect
(
'mongodb://localhost:27017/contactdb'
);
const
db
=
mongoose
.
connection
;
// let lo = function toLower(v) {
// return v.toLowerCase();
// }
function
toLower
(
v
)
{
return
v
.
toLowerCase
();
}
const
contactSchema
=
mongoose
.
Schema
({
fname
:
{
type
:
String
,
set
:
toLower
},
lname
:
{
type
:
String
,
set
:
toLower
},
phone
:
{
type
:
String
,
set
:
toLower
},
email
:
{
type
:
String
,
set
:
toLower
}
});
const
Contact
=
mongoose
.
model
(
'Contact'
,
contactSchema
);
const
addContact
=
(
contact
)
=>
{
Contact
.
create
(
contact
,
(
err
)
=>
{
// assert.equal(null, err); //check null & err
console
.
info
(
'เพิ่มรายการติดต่อใหม่สำเร็จ'
);
db
.
close
();
});
};
const
getContact
=
(
name
)
=>
{
const
search
=
new
RegExp
(
name
,
'i'
);
Contact
.
find
({
$or
:
[{
fname
:
search
},
{
lname
:
search
}]
})
.
exec
((
err
,
contact
)
=>
{
// assert.equal(null, err);
console
.
info
(
contact
);
//return contact type ==> list
console
.
info
(
`ค้นเจอทั้งหมด
${
contact
.
length
}
รายการ`
);
db
.
close
();
});
};
// exports.toLower = lo;
module
.
exports
=
{
addContact
,
getContact
};
\ No newline at end of file
week04/contact-manager/note in class.txt
0 → 100644
View file @
a8bb0973
nvm => node version management
nmv ใช้จัดการเวอร์ชันของโหนดเช่นดาวน์โหลดโหนดเวอร์ชั่นที่จะใช้
หรือเลือกว่าจะใช้โหนดเวอร์ชั่นอะไรในการใช้งานหรือพัฒนา
yarn add == npm install
inquirer commander คืออะไร
MIT licence คือ ??
https://naiwaen.debuggingsoft.com/2015/06/incorrect-about-open-source/
process คือ module ที่ช่วยให้เราเอาไว้จัดการกับ process
process มีให้อยู่แล้วใน node เหมือน console.log() นั่นแหล่ะ
promise คือสัญญา -> เมื่อทำเสร็จแล้วจะให้อะไรกลับมา
nmap -> ใช้ตรวจสอบพอร์ตที่เครื่องเราเปิดอยู่
\ No newline at end of file
week04/contact-manager/package.json
0 → 100644
View file @
a8bb0973
{
"name"
:
"contact"
,
"version"
:
"1.0.0"
,
"description"
:
"A command-line contact management system"
,
"main"
:
"index.js"
,
"author"
:
"nize"
,
"license"
:
"MIT"
,
"preferGlobal"
:
true
,
"bin"
:
"./index.js"
,
"dependencies"
:
{
"commander"
:
"^2.14.0"
,
"inquirer"
:
"^5.1.0"
,
"mongoose"
:
"^5.0.3"
}
}
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