简体   繁体   中英

Document download counter? Using Node.js, express, mongo, mongoose

I'm working on a medium size company's intranet. The website is hosted on-site, and will have many links to documents hosted on the same server. Does anybody know what's the best/easiest way to keep count of downloads of each document? Website developed using Node.js, express, mongo, mongoose.

Simplest thing to do would be to just have a mongo document holding the metadata about each file, and then increment the “downloads” field of that every time it's downloaded.

Slightly harder but probably more useful would be to log info about each download either in its own mongo record or to the system logs. In that case you're going to capture things like which user, when, etc, which you'd then count to get the total, but you could also do things like see which user did it or more complex things like which department is doing the most downloading, etc.

To keep track of all that are using your file, that you can do is that keep a logger as middleware in express as a result you will be a find who all have access to file by searching the log. morgan is a good logger which helps you this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM