Advertisement
Guest User

Untitled

a guest
Feb 12th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. // server.js
  2. var process = require('child_process');
  3. var fs = require('fs');
  4. var db_rwp = process.fork('db_rwp.js');
  5. db_rwp.on('message', function(data) {
  6. switch(data.acid){
  7. /* INIT : ERROR */ case 'error':
  8. console.log(' # database reader / writer ERROR ');
  9. console.log(data.arg1);
  10. break;
  11. /* INIT : OK! */ case 'success':
  12. console.log(' # database reader / writer : 0N ');
  13. break;
  14. }
  15. });
  16.  
  17. // db_rwp.js
  18. var mysql = require('mysql');
  19. var fs = require('fs');
  20. //When Spawned Return Connection Status
  21. var db = mysql.createConnection({
  22. host:'host', user:'user', password:'pass', database: 'database'
  23. });
  24. db.connect(function(err){
  25. if (err) { process.send({acid:'error',arg1:err}); }
  26. else { process.send({acid:'success'});}
  27. });
  28.  
  29. // server.js -to- db_rwp.js :
  30. db_rwp.send({acid:'action_id', csid:socket.id});
  31. // db_rwp.js -to- server.js :
  32. process.send({acid:'action_id', csid:data.csid});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement