Commit 14df512f authored by sirilak's avatar sirilak

week12-13

parent 273e915c
ilduangdee/nodej_
senierproject @ d82c5cf1
Subproject commit d82c5cf1ca9d4b191908b71cb0b30c7adf47824f
console.log('hello world');
console.log('hello %s', 'world');
// Prints: hello world, to stdout
const name = 'Will Robinson';
console.warn(`Danger ${name}! Danger!`);
// Prints: Will Robinson
/*const MESSAGE = "hello world ";
let name String= "BB";
console.info(MESSAGE);*/
/*
--------------------------------------------------
const readline = require('readline');
const fs = require('fs');
const rl = readline.createInterface({
input: fs.createReadStream('package.json'),
crlfDelay: Infinity
});
rl.on('line', (line) => {
//พฤติกรรมของฟังก์ช
console.log(`ผู้ใช้กรอกข้อมูลแล้ว: ${line}`);
});
--------------------------------------------------------------
*/
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('กรอกชื่อ ', (answer) => {
// TODO: Log the answer in a database
console.log(`สวัสดี: ${answer}`);
rl.close();
});
{
"name": "student",
"version": "0.1.0",
"lockfileVersion": 1
}
{
"name": "student",
"version": "0.1.0",
"description": "display student information given nickname for partially entered fullname",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": " http://projectcs.sci.ubu.ac.th/nilduangdee/nodejs-60-2"
},
"keywords": [
"students",
"nodejs",
"comsci",
"ubu"
],
"author": "csubu",
"license": "ISC"
}
let name = "Bee";
console.log(`Hello ${name}.`);
{
"name": "weeek01",
"version": "0.1.0",
"description": "ขอสองคะแนน",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"repository": {
"type": "git",
"url": "http://projectcs.sci.ubu.ac.th/nilduangdee/nodejs-60-2/week01/package.json:"
},
"keywords": [
"การบ้าน"
],
"author": "nilduangdee",
"license": "ISC"
}
// // //console.log('sirilak');
// // //console.log('hello %s', 'world');
// // // Prints: hello world,
// // r.question('กรอกชื่อ', (name) => {
// // r.question('ปีเกิด พ.ศ.', (year) => {
// //----------------------------------------------------------------------------------//
// const rl = require('readline');
// const r = rl.createInterface(input = process.stdin)
// year = 2561 - year;
// r.question('ขอเบอร์ด่วน', (phone) => {
// console.log(`คุณ${ name }อายุ${ year } เบอร์ ${phone}.`)
// r.close()
// })
// })
// })
// //การเรียกชื่อ อายุ เบอร์
// //----------------------------------------------------------------------------------------
// const rl = require('readline');
// let label =['name','year','phon']
// let data=[]
// const r = rl.createInterface(input = process.stdin)
// let i = 1
// r.on('line', (line) => {
// data[label[i]] = line
// console.log(`line == ${line} and i = ${i}`)
// i++;
// if (i == 3) {
// console.log('label',label)
// label[9]='Holy Cow!'
// console.log('label',label)
// console.log('data',data)
// r.close()
// }
// })
// r.on('close', () => r.close())
// //การเรียกชื่อ บอกจำนวนแถว
// //----------------------------------------------------------------------------
// const readline = require('readline');
// const rl = readline.createInterface({
// input: process.stdin,
// output: process.stdout
// });
// rl.question('กรอกชื่อ ', (answer) => {
// console.log(`สวัสดี: ${answer}`);
// rl.close();
// });
//-----------------------------------------------------------------------------
const rl = require('readline');
const r = rl.createInterface(input = process.stdin)
let i = 0
let data = []
r.on('line', (line) => {
data[i]= line
i++
if(i == 3) {
data[1] = 2561-data[1]
console.log(`สวัสดีคุณ ${data[0]} คุณอายุ ${data[1]} ปี เบอร์ ${data[2]}`)
r.close()
}
})
\ No newline at end of file
node_module/
\ No newline at end of file
\ No newline at end of file
#!/usr/bin/env node
//const { addContact,getContact}=require('./logic');
// function toLower(v){
// return v.toLowerCase();
// }console.log(toLower("Sirilak Phoenix"))
const program = require('commander');
const lo = require('./logic')
program
.version('0.0.1')
.description('Contact management system');
// program.parse(process.argv);
// program
// .command('addContact <firstame> <lastname> <phone> <email>')
// .alias('a')
// .description('Add a contact')
// .action((firstname, lastname, phone, email) => {
// //addContact({firstname, lastname, phone, email});
// console.log('user wants to addContact');
// });
// program.parse(process.argv); การกรอกข้อมูลชื่อ เบอร์ อีเมลล์
program
.command('Programmer ')
.alias('p')
.description('ดูข้อมูลโปรแกรมเมอร์')
.action(() => {
console.log(`programmer คือ ศิริลักษณ์`);
});
console.log(process.argv);
// program.parse(process.argv);
\ No newline at end of file
function toLower(v) {
return v.toLowerCase();
}
const mongoose = require('mongoose');
mongoose.Promise = global.Promise;
// let lower = toLower;
// exports .toLower = let;
// index.js
// const lower = require("logic")
// console.log(lower.toLower("Sirilak Phoenix"))
// logic.js[+]
//const program = require('mongodb');
const db = mongoose.connect('mongodb://localhost:27017/contactdb');
const contactSchema = mongoose.Schema({
firstname: {
type: String,
set: toLower
},
lastname: {
type: String,
set: toLower
},
phone: {
type: String,
set: toLower
},
email: {
type: String,
set: toLower
}
});
const Contact = mongoose.model('Contact', contactSchema);
const addContact = (contact) => {
console.info('กำลัง เพิ่มรายการติดต่อ${contact}');
Contact.create(contact, (err) => {
console.info('เพิ่มรายการติดต่อใหม่ สำเร็จ');
db.disconnect();
});
};
const getContact = (name) => {
// Define search criteria
const search = new RegExp(name, 'i');
Contact.find({
$or: [{
firstname: search
}, {
lastname: search
}]
})
.exec((err, contact) => {
assert.equal(null, err);
console.info(contact);
console.info(`ค้นเจอทั้งหมด${contact.length} matches รายการ`);
db.disconnect();
});
};
module.exports = {
addContact,
getContact
};
\ No newline at end of file
{
"name": "contact-manager",
"version": "1.0.0",
"description": "ทำตามเขา",
"main": "index.js",
"author": "sirilak",
"license": "MIT",
"preferGlobal": true,
"bin" : "./contact",
"dependencies": {
"commander": "^2.14.0",
"inquirer": "^5.1.0",
"mongoose": "^5.0.3"
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment