Question

How can I install python in a nodejs app?

In my nodejs application I use a library that needs python, for this reason I need it installed in my app together with nodejs. How can I do it?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

KFSys
Site Moderator
Site Moderator badge
April 20, 2023

Hey @a73f776eefc546709cb0576d5f4284,

I’ll recommend checking this docs page :

https://docs.digitalocean.com/products/app-platform/reference/buildpacks/nodejs/

When you give App Platform access to your code, it defaults to using a Dockerfile if one is present in the root of the directory or specified in the app spec. Otherwise, App Platform checks your code to determine what language or framework it uses. If it supports the language or framework, it chooses an appropriate resource type and uses the proper buildpack to build the app and deploy a container.

heroku-buildpack-nodejs is utilized as the buildpack for detecting and building your NodeJS applications.

Use Dockerfile

To add Python to your Node.js app in DigitalOcean App Platform, you can create a custom Dockerfile that includes both Node.js and Python.

Something like this should work:

  1. # Use an official Node.js runtime as a parent image
  2. FROM node:14
  3. # Set the working directory to /app
  4. WORKDIR /app
  5. # Install Python
  6. RUN apt-get update && apt-get install -y python3
  7. # Copy the package.json and package-lock.json files to the working directory
  8. COPY package*.json ./
  9. # Install the dependencies
  10. RUN npm install
  11. # Copy the rest of the application code to the working directory
  12. COPY . .
  13. # Start the application
  14. CMD [ "npm", "start" ]

This Dockerfile installs Python 3 and sets the working directory to “/app”. It then copies the package.json and package-lock.json files to the working directory, installs the dependencies with npm install, and copies the rest of the application code to the working directory. Finally, it starts the application with npm start.

You’ll need to add the Dockerfile to your GitHub repo and redeploy the app.

Hope that helps!

KFSys
Site Moderator
Site Moderator badge
April 20, 2023

This comment has been deleted

    Try DigitalOcean for free

    Click below to sign up and get $200 of credit to try our products over 60 days!

    Sign up