Answer the question
In order to leave comments, you need to log in
How to save stream in Node.js?
How can a stream be stored in Node.js other than in memory? Tried using Redis but it only works with strings, dates and buffers. Current code example:
const Docker = require('dockerode');
const streams = {};
exports.startTerminal = async (id, socket) => {
const container = docker.getContainer(id);
try {
const inspectData = await container.inspect();
const isRunning = inspectData.State.Running;
if (!isRunning) await container.start();
const stream = await container.attach({ stream: true, stdin: true, stdout: true, stderr: true });
socket.emit('terminal-started');
stream.write('reset\n');
stream.on('data', chunk => {
socket.emit('terminal-output', chunk.toString('utf8'));
});
streams[id] = stream;
} catch(err) {}
};
exports.terminalInput = (data, id, socket) => {
const stream = streams[id];
stream.write(data);
};
Answer the question
In order to leave comments, you need to log in
Yes, because it's just a network connection, nothing more. If the container is lost, then in any case it must be recognized as dead
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question