How to deploy molecular project without docker in production?

400 views Asked by At

How should I deploy a molecular microservice project on the server without using docker and Kubernetes?

I pull my updated code into a server and run the npm run dev command project run as per aspected.

But now I want to set up pm2 for this project so, what do I need to do?

I try to run npm run start command on a server but I am getting below output and the project is not running.

enter image description here

Please help.

3

There are 3 answers

0
Amit patel On BEST ANSWER

I got the solution.

If we not use the Docker and Kubernetes for moleclar project and directly clone our code on server same as like normal NodeJS(Express) project.

Then we need to create index.js file and need to put below lines.

const { ServiceBroker } = require('moleculer');
const config = require('./moleculer.config');

config.hotReload = true;

const broker = new ServiceBroker(config);

broker.loadServices('services', '**/*.service.js');
broker.start();

So, using above command Molecular started all the service of our project

After, index file we can able to start our project using pm2 service.

5
Icebob On

Your problem is that you didn't configure the services to start. For Docker and Kubernetes environment, we use SERVICES env variable to configure what services should be loaded on a Moleculer node.

So you can also use this way, or modify the start script in package.json and set the services what you want to load. E.g.

moleculer-runner -e services/**/*.service.js
0
Moses Maru On

I created a start script (api-init.json) as below:

[
    {
        "script": "./node_modules/moleculer/bin/moleculer-runner.js",
        "args": "services",
        "instances": "max",
        "watch": false,
        "name": "API"
    }
]

Then use pm2 to start:

pm2 start api-init.json