I think you might be able to use `path.basename` for this and make it a little easier.

    template.__filename = path.basename(filename);