A lightweight Node.js based file server for modern apps
npm install nextdrive
import NextDriveServer from 'nextdrive';
const server = new NextDriveServer({
port:3000,
apiKey: process.env.API_KEY,
});
server.start();
folder
: default to '{working dir}/uploads'
options.cors
: Allow CORS
options.allowedDomains
: Allow CORS only for certain domains
To upload files to the drive. Just send as Formdata. Rest will be handled and returns the file name to store in your db.
const formData = new FormData();
formData.append('files', file);
fetch('http://localhost:3000/upload/{foldername}',
{
method: 'POST',
body : formData,
{
headers : {
'X-API-KEY' : 'API_KEY_ADDED_IN_CONFIGS'
}
}
});
// OUTPUTS: File name & details
File access:
http://{root_url}/uploads/{foldername}/{filename}
To delete files from the drive. Send file names as an Array
const formData = new FormData();
formData.append('files', [filenames]);
fetch('http://localhost:3000/{foldername}',
{
method: 'DELETE',
body : formData,
{
headers : {
'X-API-KEY' : 'API_KEY_ADDED_IN_CONFIGS'
}
}
});