CryBaby
CryBaby

Reputation: 47

How to start a node js server when Autoscalling a EC2 instance

I have a EC2 instance which runs node js Servers but when autoscalling I want the newly generated instance to run the node Server .What can I do to make sure instances run the node server on boot

I have tried to use forever but I am not sure how to use it.Is there any way i can use cronjob to do this As of now i installed npm install forever -g and installed forever-monitor in my directory where Server.js is running

  const http = require('http');

const app = require('./app');

var accesslog = require('access-log');

const port = process.env.PORT || 9000;



const server = http.createServer(app);




server.listen(port);

Upvotes: 0

Views: 145

Answers (1)

Banjo Obayomi
Banjo Obayomi

Reputation: 1690

Create an AMI that has your script as a service, by following this guide https://timleland.com/how-to-run-a-linux-program-on-startup/

Then just have your Autoscale group launches instances with that AMI

Upvotes: 1

Related Questions