Giter VIP home page Giter VIP logo

Comments (4)

Molnfront avatar Molnfront commented on September 13, 2024

I my have a solution. I remember an application that I built a year ago where I read files from a directory outside the node servers root. I had no problems whatsoever to read new files without restarting node.js. I will do a couple of tests...

from node-directory-tree.

Molnfront avatar Molnfront commented on September 13, 2024

I did a little test by changing to a directory outside the server root. But that did not work, then I built a little function based on my own code and it works! The file list gets updated. Tested with Postman.

// test read file list!
app.get('/filelist' , function(req, res){
  var fileList = [];
  //List all files and build an array of it.
    fs.realpath(repodir + '/', function(err, path) {
      if (err) {
        console.log(err);
        return;
      }
      //console.log('Path is : ' + path);
    });
    fs.readdir(repodir + '/', function(err, files) {
      if (err) return;
    for( i in files ){
      //console.log("test" + files[i]);
      fileList.push({'name': files[i]});
    }
    // send
    res.send(JSON.stringify(fileList));
  });
});

Looks as if I have to build my own directory-tree traversal solution. I have no idea why one works and the other is not...

from node-directory-tree.

Molnfront avatar Molnfront commented on September 13, 2024

SOLVED!
My bad, my implementation of your modul was a bit wrong, I declared to many variables. So it would hold the the listing forever I guess.

var dirTree = require('directory-tree');
var repotree = dirTree.directoryTree(repodir); <--- this will hold the value forever...

Now I tested this:

res.json(dirTree.directoryTree(repodir));

And of course it worked.

from node-directory-tree.

mihneadb avatar mihneadb commented on September 13, 2024

I'm glad you figured it out! Cheers!

from node-directory-tree.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.