0

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.

Amit Patel
  • 167
  • 2
  • 12

3 Answers3

1

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
Icebob
  • 1,132
  • 7
  • 14
  • Thanks, @Icebob npm run start is running as you gave a solution. But I want to set up the pm2 service on the Molecular project for that which command I need to run. Like for normal node, we use the sudo pm2 start server(main file) command – Amit Patel Mar 24 '22 at 05:15
  • It can be called as "normal node", like `node node_modules/moleculer/bin/moleculer-runner.js -e services/**/*.service.js` – Icebob Mar 28 '22 at 17:10
  • tried, @icebob getting an error screenshot link:- https://prnt.sc/TuV9PRAg0X_d – Amit Patel Mar 29 '22 at 09:57
  • try to create a repro repo – Icebob Mar 30 '22 at 11:17
  • Sorry but I am not getting what is meaning of repro – Amit Patel Apr 01 '22 at 09:48
0

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.

Amit Patel
  • 167
  • 2
  • 12
0

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
SoF
  • 729
  • 1
  • 10
  • 24