npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fm2.api.nodejs

v0.0.8

Published

An API backend to work with fm2.

Downloads

34

Readme

fm2.api.nodejs

fm2.api.nodejs holds the Node.js api router for use with jlaustill/fm2. It isn't very useful by itself as it simply provides the backend services for the filemanager. If this doesn't make any sense to you, check out the fm2 repo.

Installation

Installation is easy with npm, from the root of your Node.js project, run

npm install fm2.api.nodejs

It will install into

./node_modules/fm2.api.nodejs/

Configuration

You'll need to edit the /dist/fm2.api.config.json file and give it your settings, the options are as follows.

  1. options.fileroot => the folder files will be saved to and retrieved from, can be anywhere on your server
  2. security.capabilities => which actions to allow, the client first asks for the servers rules, these are those rules. If you don't want to allow uploading, remove upload. Etc etc.
  3. security.allowedFileTypes => These are the only file extensions the filemanager will allow, it will ignore anything else and not allow uploads outside this list.

You will need a global variable for the application root, why this isn't a standard Node.js variable is seriously beyond me. Just copy and paste this into your app.js, or whatever file you use for your root

global.__appRoot = path.normalize(__dirname);

And install path with,

npm install --save path

Next, you will need to add path-posix to your project, just run

npm install --save path-posix

Finally, you will need to require /dist/filemanager.js and use it as a route. My call looks like this

router.use('/filemanager', require('./node_modules/fm2.api.nodejs/dist/filemanager')());

Security

fm2.api.nodejs uses Passport.js for security. If you have it configured, it will be detected and used. If you don't, it won't have an security and be wide open: I do NOT recommend this...

It does two things, first, it ensures the user is authenticated for every endpoint. If they are not, it will return an error object and provide the user with a toastr alert.

Second, it ensures that only folders matching the users roles are provided. It assumes that req.user.roles is an array of roles, if it's not, you'll need to copy your roles to that location. This is a bit tough to explain, so I'll give an example. Imagine your user has these roles

console.log(req.user.roles);
=> ["admin", "user", "finance"]

And the directory your fileroot is pointing to has the following folders

/
/admin
/user
/marketing
/finance

The user will only see the folders at the root level that match his/her roles, so marketing won't even show up. You can use this to have files only seen by your user groups, however you set them up. I use them for departments as shown

Contributing

I welcome any and all contributions! This is a pretty large project, and so far I've done it all by myself. If you have idea's, bug reports, documentation suggestions, or anything else useful open a bug report and lets hear them!

To hack on the code, just fork and clone the entire repo. I have it set up as a runnable app, so you should be able to just run it and start hacking.

License

License: MIT

Contact

Joshua Austill

Find me on my blog, there's links to my twitter etc etc.