Advertisement
Guest User

prueba

a guest
Oct 31st, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. var fs = require('fs');
  2.  
  3.  
  4. function Archivo() {
  5.  
  6. this.guardar = function(data){
  7. nombre = Math.floor(Math.random() * (999-2)) + 2;
  8.  
  9. var jsonData = JSON.stringify(data, null, " ");
  10. fs.writeFile("/tmp/json/" + nombre + ".json", jsonData, function(err) {
  11. if(err){
  12. console.log(err);
  13. }
  14. else{
  15. console.log('Se ha escrito correctamente');
  16. }
  17. });
  18. },
  19.  
  20. this.leerArchivo = function(id){
  21. var fs = require('fs');
  22. fs.readFile("/tmp/json/" + id + '.json', 'utf8', function(err, data) {
  23. if(err){
  24. console.log(err)
  25. }
  26. else{
  27. console.log(data);
  28. return data;
  29. }
  30. });
  31. },
  32.  
  33. this.LeerDirectorio = function(){
  34. }
  35. }
  36.  
  37.  
  38. module.exports = Archivo;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement