console command with readline

jl-nzHOBBY

3 months ago

hi all,

Is there a way to input console commands for my deployment, like you could with a regular node.js project locally?

the goal of what i'm doing is to be able to execute events via a console command at runtime.

Solved

0 Replies

jl-nzHOBBY

3 months ago

N/A


3 months ago

ya, you can connect to the container's console via railway ssh
(make sure you have the latest cli installed)


jl-nzHOBBY

3 months ago

awesome, thank you.

I'm currently trying to test this using the following, but it doesn't seem to be working. I'm inputting "test" into the terminal after successfully connecting to the interactive shell

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', (message) => {
    console.log(`Input received: ${message}`);    
})

Is there a step I'm missing here to have this work with ssh? This works as expected when I test locally.


3 months ago

You might have to spawn that interactive cli in the ssh cli after connecting to the container


jl-nzHOBBY

3 months ago

That sounds a bit beyond the scope of my current knowledge, is there any resource you could direct me to so that I can try figure that out?


3 months ago

you just run your node app's cli after connecting to the container


3 months ago

I'm not sure of your workflow, though personally if I had to make this then I'd have two entrypoints in my app
the main entrypoint, which is my actual application, then a second cli entrypoint that I can run myself, like node cli.js


3 months ago

-# I could be fully wrong here, I've never done this before since I've never needed to make an interactive CLI for a production application hosted elsewhere


jl-nzHOBBY

3 months ago

oh okay, i think i get what you're meaning, thanks for your help


3 months ago

np!!


jl-nzHOBBY

3 months ago

This does seem to work, though i'll have to figure out how/if i can integrate it with my existing project (for anyone who finds this via search)


3 months ago

yea true, that is the only issue with this approach though I can't think of another way to tackle this


3 months ago

(again though I've never done this before so there could be better ways but this is what I'd do personally)


3 months ago

hosting a CLI application on a web hosting platform is definitely not what railway ssh is intended to be used for


3 months ago

sometimes you gotta swat flies with a sledgehammer


3 months ago

sometimes you gotta swat flies with a sledgehammer


3 months ago

feel free to mark as solved fragly


3 months ago

!s


Status changed to Solved dev 3 months ago


console command with readline - Railway Help Station