Multi-part answer:
- If chat screen is not started then start it, otherwise close it.
screen -S chat -X quit || screen -S chat
Could also detach
rather than kill the screen session, if that's
what you meant.
- execute a command in chat session (ex: node chat.js)
If you mean to start a new screen and execute a command, then
screen -dm -S chat && screen -S chat -X stuff 'command-to-execute-in-screen-subshell
'
Note the embedded new-line inside the quotes. If the screen is already running, you can leave off the first half.
screen -S chat -X detach
see also answer to first question.
All of this is reasonably documented in the manual.