Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8446131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:50:50+00:00 2026-06-10T09:50:50+00:00

I have set a node app up on my server and i can ssh

  • 0

I have set a node app up on my server and i can ssh into my directory and run

node server.js

great server up and running fine but as soon as i close my ssh window and logout node server stops and i get io.socket no defined etc etc.

here is my server.js

var port = process.env.PORT || 1337;

var io = require('socket.io').listen(port);

var archiveMessages = {};
var channels = ['foo channel', 'bar channel'];

var chat = io.of('/chat');
chat.on('connection', function(socket){
  console.log('connected: %s', socket.id);

  // push available channel list
  socket.emit('available_channel', channels);

  socket.on('join', function(value){
    console.log('%s joined channel: %s', socket.id, value.channelId);

    socket.join(value.channelId);
    socket.set('channel_id', value.channelId, function(){
      var messages = archiveMessages[value.channelId] || [];
      socket.emit('joined', messages);
      socket.broadcast.to(value.channelId).emit('user:join', {
        id: socket.id
      });
    });
  });

  socket.on('post', function(message){
    socket.get('channel_id', function(err, channelId){
      console.log('%s says<%s channel>: %s', socket.id, channelId, message);

      if(!(channelId in archiveMessages)){
        archiveMessages[channelId] = [];
      }
      archiveMessages[channelId].push(message);

      socket.emit('posted', {
        message: message
      });
      socket.broadcast.to(channelId).emit('user:message', {
        id: socket.id,
        message: message
      });
    });
  });

  socket.on('disconnect', function(){
    console.log('%s disconnected', socket.id);
    socket.get('channel_id', function(channelId){
      socket.leave(channelId);
      socket.broadcast.to(channelId).emit('user:leave', {
        id: socket.id
      });
    });
  });
});

var image = io.of('/image');
image.on('connection', function(socket){

  socket.on('upload', function(param){
    console.log('upload base64 size: %d', param.base64.length);

    if(param.download){
      socket.emit('download', {
        base64: 's' + new Array(65534).join('0') + 'e'
      });
    }
  });
});

How can i keep this server.js running constantly.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T09:50:52+00:00Added an answer on June 10, 2026 at 9:50 am

    You need to either run your Node app as a service/daemon using Forever. Or, of you still want to run it on the shell via SSH, use something like screen or tmux.

    Using Forever:

    How does one start a node.js server as a daemon process?

    Using Screen:

    http://www.rackaid.com/resources/linux-screen-tutorial-and-how-to/

    Using Tmux:

    http://blog.hawkhost.com/2010/06/28/tmux-the-terminal-multiplexer/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have running nginx on my server ansel.ms and a node.js app on ansel.ms:46156.
I have parent/child relationship set up via Node Reference. A Child record can have
I need to set GCGraceSeconds to 0, because I have only one node, but
Okay, I have a simple test server set up using socket.io in node.js. My
I have a node.js server with socket.io: var io = require('socket.io').listen(app); // assuming io
I'm exploring using the node-http-proxy proxy server so that I can have our proxy
I have a tree structure where each Node has a parent and a Set<Node>
I have set up an app that is registered for remote notifications. - (void)application:(UIApplication*)application
I'm running node.js on OSX and have just installed mongodb using command npm install
I'm about ready to go live with my node.js/mongo app running on the Amazon

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.