stumbler
stumbler

Reputation: 737

How to execute npm run command forever

enter image description here I have an application with angular in the font end and node.js in the back end. I have deployed the application in a same server. My angular one is running forever. But back end was not running forever. From local I used to run the back end using

npm run dev-server

After some research I found that installing forever server can be the way. But when running the below command in the server I am getting error

This is the command: In unix server sudo forever -c "npm run dev-server" ./

But it gives me error.

Can anyone suggest how to run the backend node.js`` application forever withnpm run` command.

Upvotes: 1

Views: 2379

Answers (2)

fifoq
fifoq

Reputation: 203

You should not force to maintain the server on, since it won't work. A web server listens for connections in a socket and should never stop, if it's stopping is because some error.

You shouldn't use a dev server for production. If you need to publish a web page you need a http server.

Since you are working in node, I would recommend expressjs.

This is not a hard task and you can develop a server fitted to your needs.

Here you've got a simple example:

my_folder
|-server.js
|-public/

And the server.js contains:

var express = require('express');
var app = express();

app.use(express.static('public'));

app.listen(8080);

Place your files in the "public" folder. All files in this folder will be served when you ask for them in the browser.

in "my_folder" run "npm install express" and "npm start" and the server will be listening under "localhost:8080".

Upvotes: 1

gccampos
gccampos

Reputation: 11

Did you try to use Forever.js? It's a CLI tool that basically do that. The link for it is: https://www.npmjs.com/package/forever

When i need to make sure the server is always on, i use it.

Upvotes: 1

Related Questions