cancel
Showing results for 
Search instead for 
Did you mean: 

Run Python within Node JS in Cloud BTP

somnath
Active Participant
0 Kudos

Hello,

I am trying a Proof of Concept, where I will run a python application (for web scrapping) within the node js application.

This approach is something like creating a child process with node js using "spawn" and working fine from my local machine.

But failing when I deploy this to cloud BTP. This is because of the dependencies of a few resources for my python application (child process).

I have created a virtual environment and there I have installed all the dependencies as needed and so the application is running perfectly from the local machine (windows).

The manifest.yml looks like this:

I am not sure how can I add dependencies for the python application which will be running as a child process within parent wrapper node js application!

---
applications:
  - name: node-python
    command: npm run start
    random-route: true
    memory: 1024M
    disk_quota: 1024M

I am not willing to deploy a separate python-flask application and make REST calls from Node JS. This will be possible I think, but before I invest time building a Flask app, I am quite keen to know how I can resolve my current challenge.

Would be a great help, if someone suggests some pointers here.

Thanks in advance!

- Regards, Somnath

View Entire Topic
gregorw
Active Contributor
0 Kudos

Dear Somnath,

if you want to have a SAP supported solution you should use one of the buildpacks that you get listed when issuing:

cf buildpacks

An option might be the apt-buildpack that you can combine with other buildpacks as I did in mta.yaml#L28. With the configuration file db-deployer-apt/apt.yml you control what other packages are getting installed. So you could add python to the node buildpack.

Best regards
Gregor

somnath
Active Participant
0 Kudos

Thanks, Gregor for your time and for sharing your views on this!

I was not checking this thread and hence missed your answer. In the meantime, I was trying a Docker solution and it worked for me. I will definitely try out your approach also. Anyways my Dockerfile is as below:

# syntax=docker/dockerfile:1

FROM nikolaik/python-nodejs:python3.9-nodejs16-slim
WORKDIR /app

COPY requirements.txt requirements.txt
RUN apt-get update || : && apt-get install python -y
COPY . .
RUN npm install
RUN pip3 install -r requirements.txt
EXPOSE 3000
CMD ["node","index.js"]

Thank you so much again!

- Regards, Somnath

gregorw
Active Contributor

Thank you for sharing your solution.