JonAbrams/synth

How can I run a synth app without the synth cli.

mikaelhm opened this issue · 5 comments

I would like to run my synth app with the process manager pm2.

Thus, I would like to be able to modify back-app.js so I can run it with

node back/back-app.js

is this possible?

It certainly is, and I intend to document it at some point. So why not here?

Alter the back-app.js file so that instead of it returning the synth() call, you assign it to a variable. That variable is then basically like any other express app, which you can call listen on:

var port = process.env.PORT || 3000;
var app = synth(); // Initializes synth and returns app
app.listen(port, function () {
  console.log('synth is now listening on port ' + port);
});

Also, if you want to enable production mode, you can either set the environment variable NODE_ENV to "production" or you can pass in { production: true } to synth(…) as a parameter.

I should also add that if you run a synth app this way, then you miss out on the auto-restarting feature when it detects a changed local file. But you can always roll your own solution for that with something like nodemon

Thanks!
This is mainly intended for production. But nodemon is a good point though.

I ended up making a new app.js file

var app = require('./back-app');

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

app.listen(port, function () {
  console.log('synth is now listening on port ' + port);
});

Clever, that totally works and you can still use the synth cli, nice! I'll recommend this method whenever I get around to documenting it :)

Hi

To debug my app using node inspector, I had to create an app.js file like above in the application root dir (where the back and front folders are located). I changed the first line to:

var app = require('./back/back-app'); 

Then I run node-inspector:

node-inspector

and launch my app in another terminal:

node --debug app.js

The default way of running node inspector does not work. This is not a problem, I just wanted to document it :)