-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (29 loc) · 837 Bytes
/
index.js
File metadata and controls
36 lines (29 loc) · 837 Bytes
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
/**
* Created by fahziar on 02/09/2015.
*/
var readline = require('readline');
var firebase = require('firebase');
var username = "";
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var cobaChat = new firebase('https://coba-js.firebaseio.com/messages');
rl.question("Enter your name\n", function (answer) {
username = answer;
console.log("Hello, " + answer);
startChat();
});
function startChat(){
cobaChat.limitToLast(5).on("child_added", function(snapshot, prevChildKey) {
var newPost = snapshot.val();
console.log(newPost.username + ': ' + newPost.message);
});
console.log("You can start chat now");
rl.on('line', function (line) {
cobaChat.push({
username: username,
message: line
});
});
}