Meteor - Create a new folder in the public directory on account creation

808 views Asked by At

I'm working on a meteor project and one of its functionality is for users to upload their pictures in their profile. I wanted to create a new folder in the public directory (i.e public/img/user_id/files_to_upload_here.jpg), every time a new user is created.

Accounts.onCreateUser(function(options, user) {
    //code to create a folder
});

How can I achieve that?

Thanks!

2

There are 2 answers

0
Tobias On

This is not the way to go. Use a filesystem like CollectionFS instead:

https://github.com/CollectionFS/Meteor-CollectionFS

2
Julien Leray On

I think you can directly use the function from the node API:

var fs = require('fs');
var dir = './directory';

fs.mkdirSync(dir);

Doc

You also have the async method which do the same.