You can integrate Cloud Commander into an existing Node.js application using Express and Socket.IO. This allows you to mount the file manager at a specific route prefix.
Prerequisites
Install the required dependencies:
npm init -y
npm i cloudcmd express socket.io -S
Implementation
To use it, create an HTTP server, initialize a Socket.IO server, and pass the socket instance to the cloudcmd middleware. You can also provide a config object, custom modules, and a configManager to customize the instance.
import http from 'node:http';
import {cloudcmd} from 'cloudcmd';
import {Server} from 'socket.io';
import express from 'express';
const app = express();
const port = 1337;
const prefix = '/';
const server = http.createServer(app);
const socket = new Server(server, {
path: `${prefix}socket.io`,
});
const config = {
name: 'cloudcmd :)',
};
const modules = {};
const {
createConfigManager,
configPath
} = cloudcmd;
const configManager = createConfigManager({
configPath,
});
app.use(prefix, cloudcmd({
socket, // required for Console and Edit
config, // optional
modules, // optional
configManager, // optional
}));
server.listen(port);