Showing
43 changed files
with
70 additions
and
530 deletions
1 | -var express = require('express'); | ||
2 | -var app = express(); | ||
3 | -var bodyParser = require('body-parser'); | ||
4 | - | ||
5 | -app.use(bodyParser.urlencoded({ extended: false })); | ||
6 | -app.use(bodyParser.json()); | ||
7 | - | ||
8 | - | ||
9 | -var books = new Array(); | ||
10 | - | ||
11 | -app.get('/books/:bookId', function (req, res) { | ||
12 | - var bookId = req.params.bookId; | ||
13 | - console.log(books[bookId]); | ||
14 | - res.send(books[bookId]); | ||
15 | -}); | ||
16 | - | ||
17 | -/* | ||
18 | - * json representation of book object | ||
19 | -{ | ||
20 | - "id" : 2, | ||
21 | - "name" : "book2", | ||
22 | - "price" : 2000, | ||
23 | - "author" : "jin" | ||
24 | -} | ||
25 | -*/ | ||
26 | -app.post('/books', function (req, res) { | ||
27 | - // Create book information | ||
28 | - books[req.body.id] = [req.body.id, req.body.name, req.body.price, req.body.author]; | ||
29 | - res.send(books[req.body.id]); | ||
30 | -}) | ||
31 | - | ||
32 | -app.put('/books', function (req, res) { | ||
33 | - // Update book information | ||
34 | - | ||
35 | -}) | ||
36 | - | ||
37 | - | ||
38 | -app.delete('/books/:bookId', function (req, res) { | ||
39 | - // Delete book information | ||
40 | - | ||
41 | -}) | ||
42 | -var server = app.listen(80); | ||
43 | - console.log(books); |
1 | -{ | ||
2 | - "name": "assignment01", | ||
3 | - "version": "1.0.0", | ||
4 | - "description": "", | ||
5 | - "main": "index.js", | ||
6 | - "scripts": { | ||
7 | - "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | - }, | ||
9 | - "author": "", | ||
10 | - "license": "ISC", | ||
11 | - "dependencies": { | ||
12 | - "body-parser": "^1.17.1", | ||
13 | - "express": "^4.15.2" | ||
14 | - } | ||
15 | -} |
1 | -var express = require('express'); | ||
2 | -var app = express(); | ||
3 | -var bodyParser = require('body-parser'); | ||
4 | -var session = require('express-session') | ||
5 | - | ||
6 | -app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})) | ||
7 | -app.use(bodyParser.urlencoded({ extended: false })); | ||
8 | -app.use(bodyParser.json()); | ||
9 | - | ||
10 | - | ||
11 | -var users = new Array(); | ||
12 | -users[0] = { | ||
13 | - "userId" : 0, | ||
14 | - "name" : "jin", | ||
15 | - "password" : "abc", | ||
16 | - "isAdmin" : true | ||
17 | -} | ||
18 | - | ||
19 | -app.put('/login', function (req, res) { | ||
20 | - // users 배열에서 찾도록 처리 해야 함 | ||
21 | - // admin 여부를 확인하여 체크 | ||
22 | - // req.body.id : ID | ||
23 | - // req.body.name : 패스워드 | ||
24 | - | ||
25 | - res.send("Login"); | ||
26 | -}); | ||
27 | - | ||
28 | -app.put('/logout', function (req, res) { | ||
29 | - // Logout | ||
30 | - // 세션 유효 여부를 체크하고 세션 Delete | ||
31 | - req.session.userId = null; | ||
32 | - res.send("LogOut"); | ||
33 | - | ||
34 | -}); | ||
35 | - | ||
36 | -var auth = function (req, res, next) { | ||
37 | - // Session Check | ||
38 | - // 어드민 여부 체크 필요 | ||
39 | - if (req.session.userId != null) | ||
40 | - next(); | ||
41 | - else | ||
42 | - res.send("Error"); | ||
43 | - | ||
44 | -}; | ||
45 | -app.get('/user/:userId', auth,function (req, res) { | ||
46 | - // get User Information | ||
47 | - res.send("OK"); | ||
48 | -}); | ||
49 | - | ||
50 | -// 사용자 추가 시에 admin 여부도 추가해야 함 | ||
51 | - | ||
52 | -var server = app.listen(80); |
1 | -{ | ||
2 | - "name": "assignment02", | ||
3 | - "version": "1.0.0", | ||
4 | - "description": "", | ||
5 | - "main": "index.js", | ||
6 | - "scripts": { | ||
7 | - "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | - }, | ||
9 | - "author": "", | ||
10 | - "license": "ISC", | ||
11 | - "dependencies": { | ||
12 | - "body-parser": "^1.17.1", | ||
13 | - "express": "^4.15.2", | ||
14 | - "express-session": "^1.15.2" | ||
15 | - } | ||
16 | -} |
1 | -var express = require('express'); | ||
2 | -var app = express(); | ||
3 | - | ||
4 | -app.get('/', function (req, res) { | ||
5 | - res.send('hello world'); | ||
6 | -}) | ||
7 | - | ||
8 | -app.route('/book') | ||
9 | - .get(function (req, res) { | ||
10 | - res.send('Get a random book'); | ||
11 | - }) | ||
12 | - .post(function (req, res) { | ||
13 | - res.send('Add a book'); | ||
14 | - }) | ||
15 | - .put(function (req, res) { | ||
16 | - res.send('Update the book'); | ||
17 | - }); | ||
18 | - | ||
19 | - | ||
20 | -var server = app.listen(23023); |
1 | -var express = require('express'); | ||
2 | -var app = express(); | ||
3 | -app.get('/', function (req, res) { | ||
4 | - res.send('Hello World'); | ||
5 | -}) | ||
6 | - | ||
7 | -var server = app.listen(23023, function () { | ||
8 | - var host = server.address().address | ||
9 | - var port = server.address().port | ||
10 | - console.log("Example app listening at http://%s:%s", host, port) | ||
11 | -}) | ||
12 | - |
1 | -var express = require('express'); | ||
2 | -var app = express(); | ||
3 | - | ||
4 | -app.get('/b', function (req, res, next) { | ||
5 | - console.log('the response will be sent by the next function ...') | ||
6 | - next() | ||
7 | -}, function (req, res) { | ||
8 | - res.send('Hello from B!') | ||
9 | -}) | ||
10 | - | ||
11 | -var cb0 = function (req, res, next) { | ||
12 | - console.log("call by cb0"); | ||
13 | - next() | ||
14 | -} | ||
15 | -var cb1 = function (req, res, next) { | ||
16 | - console.log("call by cb1"); | ||
17 | - res.send('Hello from C!') | ||
18 | -} | ||
19 | -app.get('/c', [cb0, cb1]) | ||
20 | - | ||
21 | -var server = app.listen(23023); |
1 | -{ | ||
2 | - "name": "render", | ||
3 | - "version": "1.0.0", | ||
4 | - "description": "", | ||
5 | - "main": "index.js", | ||
6 | - "scripts": { | ||
7 | - "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | - }, | ||
9 | - "author": "", | ||
10 | - "license": "ISC", | ||
11 | - "dependencies": { | ||
12 | - "ejs": "^2.5.6", | ||
13 | - "express": "^4.15.2" | ||
14 | - } | ||
15 | -} |
1 | -var express = require('express'); | ||
2 | -var app = express(); | ||
3 | - | ||
4 | -// The routing path matches requests to /about | ||
5 | -app.get('/about', function (req, res) { | ||
6 | - res.send('about') | ||
7 | -}) | ||
8 | - | ||
9 | -// The routing path matches requests to /random.text | ||
10 | -app.get('/random.text', function (req, res) { | ||
11 | - res.send('random.text') | ||
12 | -}) | ||
13 | - | ||
14 | -// This route path matches abcd, abxcd, abRANDOMcd, ab123cd, and so on. | ||
15 | -app.get('/ab*cd', function (req, res) { | ||
16 | - res.send('ab*cd') | ||
17 | -}) | ||
18 | - | ||
19 | -var server = app.listen(23023); |
1 | -var express = require('express'); | ||
2 | -var app = express(); | ||
3 | - | ||
4 | -var session = require('express-session') | ||
5 | - | ||
6 | -app.use(session({ secret: 'keyboard cat', cookie: { maxAge: 60000 }})) | ||
7 | - | ||
8 | - | ||
9 | - | ||
10 | -app.get('/', function(req, res, next) { | ||
11 | - var sess = req.session; | ||
12 | - console.log(req.session); | ||
13 | - if (sess.views) { | ||
14 | - sess.views++; | ||
15 | - res.send("session Views " + sess.views); | ||
16 | - res.send(); | ||
17 | - } else { | ||
18 | - req.session.views = 1; | ||
19 | - res.send("welcome to the session demo. refresh!"); | ||
20 | - res.end(); | ||
21 | - } | ||
22 | -}); | ||
23 | - | ||
24 | -var server = app.listen(23023); |
1 | -{ | ||
2 | - "name": "session", | ||
3 | - "version": "1.0.0", | ||
4 | - "description": "", | ||
5 | - "main": "index.js", | ||
6 | - "scripts": { | ||
7 | - "test": "echo \"Error: no test specified\" && exit 1" | ||
8 | - }, | ||
9 | - "author": "", | ||
10 | - "license": "ISC", | ||
11 | - "dependencies": { | ||
12 | - "express": "^4.15.2", | ||
13 | - "express-session": "^1.15.2" | ||
14 | - } | ||
15 | -} |
1 | -var express = require('express'); | ||
2 | -var app = express(); | ||
3 | - | ||
4 | -app.all('/', function (req, res, next) { | ||
5 | - console.log('Accessing the secret section ...') | ||
6 | - next() // pass control to the next handler | ||
7 | -}) | ||
8 | - | ||
9 | -app.get('/', function (req, res) { | ||
10 | - res.send('hello world'); | ||
11 | -}) | ||
12 | - | ||
13 | -app.post('/', function (req, res) { | ||
14 | - res.send('POST request to the homepage') | ||
15 | -}) | ||
16 | - | ||
17 | -var server = app.listen(23023); |
6.72 KB
1 | // 모듈을 읽어 들입니다. | 1 | // 모듈을 읽어 들입니다. |
2 | -const request = require('request'); | 2 | +const request = require('request');//request라는 모듈로 http를 노드에서 통신할 수 있게 |
3 | // 요청을 위한 상수를 선언합니다: TOKEN은 자신의 것을 입력해주세요. | 3 | // 요청을 위한 상수를 선언합니다: TOKEN은 자신의 것을 입력해주세요. |
4 | -const TARGET_URL = 'https://notify-api.line.me/api/notify'; | 4 | +const TARGET_URL = 'https://notify-api.line.me/api/notify';//notify api의 주소 |
5 | -const TOKEN = '///채워주세요///'; | 5 | +const TOKEN = 'JSroU3MtclQ9bOZEL93Sn10X0NOcOQH0YenlJ7E6UHE'; |
6 | // 요청합니다. | 6 | // 요청합니다. |
7 | request.post( | 7 | request.post( |
8 | { | 8 | { | ... | ... |
... | @@ -2,8 +2,8 @@ const request = require('request'); | ... | @@ -2,8 +2,8 @@ const request = require('request'); |
2 | const TARGET_URL = 'https://api.line.me/v2/bot/message/push' | 2 | const TARGET_URL = 'https://api.line.me/v2/bot/message/push' |
3 | const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' | 3 | const MULTI_TARGET_URL = 'https://api.line.me/v2/bot/message/multicast' |
4 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' | 4 | const BROAD_TARGET_URL = 'https://api.line.me/v2/bot/message/broadcast' |
5 | -const TOKEN = '채널 토큰으로 교체' | 5 | +const TOKEN = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU=' |
6 | -const USER_ID = '사용자의 ID, 메세지 수신 시에 확인할 수 있음' | 6 | +const USER_ID = 'U484f0bb741ba39b93dcba8dbb731860d' |
7 | 7 | ||
8 | // Single User | 8 | // Single User |
9 | // request.post( | 9 | // request.post( |
... | @@ -77,3 +77,4 @@ const USER_ID = '사용자의 ID, 메세지 수신 시에 확인할 수 있음' | ... | @@ -77,3 +77,4 @@ const USER_ID = '사용자의 ID, 메세지 수신 시에 확인할 수 있음' |
77 | },(error, response, body) => { | 77 | },(error, response, body) => { |
78 | console.log(body) | 78 | console.log(body) |
79 | }); | 79 | }); |
80 | + | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -199,6 +199,11 @@ | ... | @@ -199,6 +199,11 @@ |
199 | "verror": "1.10.0" | 199 | "verror": "1.10.0" |
200 | } | 200 | } |
201 | }, | 201 | }, |
202 | + "lodash": { | ||
203 | + "version": "4.17.15", | ||
204 | + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", | ||
205 | + "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" | ||
206 | + }, | ||
202 | "mime-db": { | 207 | "mime-db": { |
203 | "version": "1.44.0", | 208 | "version": "1.44.0", |
204 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", | 209 | "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", |
... | @@ -264,6 +269,34 @@ | ... | @@ -264,6 +269,34 @@ |
264 | "uuid": "^3.3.2" | 269 | "uuid": "^3.3.2" |
265 | } | 270 | } |
266 | }, | 271 | }, |
272 | + "request-promise-core": { | ||
273 | + "version": "1.1.3", | ||
274 | + "resolved": "https://registry.npmjs.org/request-promise-core/-/request-promise-core-1.1.3.tgz", | ||
275 | + "integrity": "sha512-QIs2+ArIGQVp5ZYbWD5ZLCY29D5CfWizP8eWnm8FoGD1TX61veauETVQbrV60662V0oFBkrDOuaBI8XgtuyYAQ==", | ||
276 | + "requires": { | ||
277 | + "lodash": "^4.17.15" | ||
278 | + } | ||
279 | + }, | ||
280 | + "request-promise-native": { | ||
281 | + "version": "1.0.8", | ||
282 | + "resolved": "https://registry.npmjs.org/request-promise-native/-/request-promise-native-1.0.8.tgz", | ||
283 | + "integrity": "sha512-dapwLGqkHtwL5AEbfenuzjTYg35Jd6KPytsC2/TLkVMz8rm+tNt72MGUWT1RP/aYawMpN6HqbNGBQaRcBtjQMQ==", | ||
284 | + "requires": { | ||
285 | + "request-promise-core": "1.1.3", | ||
286 | + "stealthy-require": "^1.1.1", | ||
287 | + "tough-cookie": "^2.3.3" | ||
288 | + } | ||
289 | + }, | ||
290 | + "rquest": { | ||
291 | + "version": "0.1.0", | ||
292 | + "resolved": "https://registry.npmjs.org/rquest/-/rquest-0.1.0.tgz", | ||
293 | + "integrity": "sha512-gIG0JFuiAKvcKLl1H93JO/pliB/eUHTRRoJ+AyGEcEh8ub68WsV7gc87HVUX6q+6bU8ErYdDESS6NHeSMba5LQ==", | ||
294 | + "requires": { | ||
295 | + "request": "^2.85.0", | ||
296 | + "request-promise-native": "^1.0.5", | ||
297 | + "seventh": "^0.7.3" | ||
298 | + } | ||
299 | + }, | ||
267 | "safe-buffer": { | 300 | "safe-buffer": { |
268 | "version": "5.2.1", | 301 | "version": "5.2.1", |
269 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", | 302 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", |
... | @@ -274,6 +307,19 @@ | ... | @@ -274,6 +307,19 @@ |
274 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", | 307 | "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", |
275 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" | 308 | "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" |
276 | }, | 309 | }, |
310 | + "setimmediate": { | ||
311 | + "version": "1.0.5", | ||
312 | + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", | ||
313 | + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" | ||
314 | + }, | ||
315 | + "seventh": { | ||
316 | + "version": "0.7.35", | ||
317 | + "resolved": "https://registry.npmjs.org/seventh/-/seventh-0.7.35.tgz", | ||
318 | + "integrity": "sha512-8uGsybZk/XBSv7BvyjbSeK+R8vpWh2jkZJq0UIMVlJTr9CZsCLTfGWKtcBxmHzMUbzSPxa134prhvZA8GuIx/w==", | ||
319 | + "requires": { | ||
320 | + "setimmediate": "^1.0.5" | ||
321 | + } | ||
322 | + }, | ||
277 | "sshpk": { | 323 | "sshpk": { |
278 | "version": "1.16.1", | 324 | "version": "1.16.1", |
279 | "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", | 325 | "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.16.1.tgz", |
... | @@ -290,6 +336,11 @@ | ... | @@ -290,6 +336,11 @@ |
290 | "tweetnacl": "~0.14.0" | 336 | "tweetnacl": "~0.14.0" |
291 | } | 337 | } |
292 | }, | 338 | }, |
339 | + "stealthy-require": { | ||
340 | + "version": "1.1.1", | ||
341 | + "resolved": "https://registry.npmjs.org/stealthy-require/-/stealthy-require-1.1.1.tgz", | ||
342 | + "integrity": "sha1-NbCYdbT/SfJqd35QmzCQoyJr8ks=" | ||
343 | + }, | ||
293 | "tough-cookie": { | 344 | "tough-cookie": { |
294 | "version": "2.5.0", | 345 | "version": "2.5.0", |
295 | "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", | 346 | "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", | ... | ... |
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | const request = require('request'); | 2 | const request = require('request'); |
3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
4 | -const TOKEN = '채널 토큰으로 변경' | 4 | +const TOKEN = 'RbPAXRYWub0evg2yyi7oiHytZsZsE0JtbZgRYZNZDU1vjpJkOwGqwh+aKTYKVhVHh6LZOUVZLl84NQQlNWNbXR9hUhPEiLEK0cie4O3OlKUuEe/3wAsjPu7HbRi1zn9BsR3Qr4pcqmiIKP8HRUKvEwdB04t89/1O/w1cDnyilFU=' |
5 | const fs = require('fs'); | 5 | const fs = require('fs'); |
6 | const path = require('path'); | 6 | const path = require('path'); |
7 | const HTTPS = require('https'); | 7 | const HTTPS = require('https'); |
8 | -const domain = "도메인 변경" | 8 | +const domain = "www.osschat.tk" |
9 | const sslport = 23023; | 9 | const sslport = 23023; |
10 | 10 | ||
11 | const bodyParser = require('body-parser'); | 11 | const bodyParser = require('body-parser'); |
12 | var app = express(); | 12 | var app = express(); |
13 | app.use(bodyParser.json()); | 13 | app.use(bodyParser.json()); |
14 | -app.post('/hook', function (req, res) { | 14 | +app.post('/hook', function (req, res) {//hootk으로 사용자가 보낸 메세지가 들어옴 |
15 | 15 | ||
16 | var eventObj = req.body.events[0]; | 16 | var eventObj = req.body.events[0]; |
17 | var source = eventObj.source; | 17 | var source = eventObj.source; |
18 | var message = eventObj.message; | 18 | var message = eventObj.message; |
19 | 19 | ||
20 | - // request log | 20 | + // request log // |
21 | console.log('======================', new Date() ,'======================'); | 21 | console.log('======================', new Date() ,'======================'); |
22 | console.log('[request]', req.body); | 22 | console.log('[request]', req.body); |
23 | console.log('[request source] ', eventObj.source); | 23 | console.log('[request source] ', eventObj.source); |
24 | - console.log('[request message]', eventObj.message); | 24 | + console.log('[request message]', eventObj.message);//message라는 객체로 사용자의 메세지 확인가능 |
25 | 25 | ||
26 | - request.post( | 26 | + |
27 | + request.post(//답변을 보냄-위의 reply라는 api쪽으로 | ||
27 | { | 28 | { |
28 | url: TARGET_URL, | 29 | url: TARGET_URL, |
29 | headers: { | 30 | headers: { | ... | ... |
... | @@ -4,7 +4,7 @@ const path = require('path'); | ... | @@ -4,7 +4,7 @@ const path = require('path'); |
4 | const HTTPS = require('https'); | 4 | const HTTPS = require('https'); |
5 | 5 | ||
6 | const app = express(); | 6 | const app = express(); |
7 | -const domain = "www.stagefive.tk" | 7 | +const domain = "www.osschat.tk" |
8 | const sslport = 23023; | 8 | const sslport = 23023; |
9 | 9 | ||
10 | 10 | ... | ... |
... | @@ -4,12 +4,12 @@ var app = express(); | ... | @@ -4,12 +4,12 @@ var app = express(); |
4 | const fs = require('fs'); | 4 | const fs = require('fs'); |
5 | const path = require('path'); | 5 | const path = require('path'); |
6 | const HTTPS = require('https'); | 6 | const HTTPS = require('https'); |
7 | -const domain = "도메인 변경 처리" | 7 | +const domain = "www.osschat.tk" |
8 | const sslport = 23023; | 8 | const sslport = 23023; |
9 | 9 | ||
10 | -app.use(bodyParser.json()); | 10 | +app.use(bodyParser.json());//json형태로 처리 |
11 | 11 | ||
12 | -app.post('/hook', function (request, response) { | 12 | +app.post('/hook', function (request, response) {//post방식으로 들어온다. |
13 | 13 | ||
14 | var eventObj = request.body.events[0]; | 14 | var eventObj = request.body.events[0]; |
15 | var source = eventObj.source; | 15 | var source = eventObj.source; | ... | ... |
1 | -// mymodule.js에 정의된 모듈로 불러서 사용하도록 처리 |
1 | -var events = require('events'); | ||
2 | -var eventEmitter = new events.EventEmitter(); | ||
3 | -var connectHandler = function connected() { | ||
4 | - console.log('connection successful.'); | ||
5 | - eventEmitter.emit('data_received'); | ||
6 | -} | ||
7 | - | ||
8 | -eventEmitter.on('connection', connectHandler); | ||
9 | - | ||
10 | -eventEmitter.on('data_received', function(){ | ||
11 | - console.log('data received successfully.'); | ||
12 | -}); | ||
13 | - | ||
14 | -eventEmitter.emit('connection'); | ||
15 | -console.log("Program Ended."); |
1 | -var events = require('events'); | ||
2 | -var eventEmitter = new events.EventEmitter(); | ||
3 | -var listner1 = function listner1() { | ||
4 | -console.log('listner1 executed.'); | ||
5 | -} | ||
6 | -var listner2 = function listner2() { | ||
7 | -console.log('listner2 executed.'); | ||
8 | -} | ||
9 | - | ||
10 | -eventEmitter.addListener('connection', listner1); | ||
11 | -eventEmitter.on('connection', listner2); | ||
12 | -var eventListeners = require('events').EventEmitter.listenerCount(eventEmitter,'connection'); | ||
13 | -console.log(eventListeners + " Listner(s) listening to connection event"); | ||
14 | - | ||
15 | -eventEmitter.emit('connection'); | ||
16 | -eventEmitter.removeListener('connection', listner1); | ||
17 | -console.log("Listner1 will not listen now."); | ||
18 | - | ||
19 | -eventEmitter.emit('connection'); | ||
20 | -eventListeners = require('events').EventEmitter.listenerCount(eventEmitter,'connection'); | ||
21 | -console.log(eventListeners + " Listner(s) listening to connection event"); | ||
22 | -console.log("Program Ended."); |
-
Please register or login to post a comment