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?
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!
This comment has been deleted
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.
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:
- # Use an official Node.js runtime as a parent image
- FROM node:14
-
- # Set the working directory to /app
- WORKDIR /app
-
- # Install Python
- RUN apt-get update && apt-get install -y python3
-
- # Copy the package.json and package-lock.json files to the working directory
- COPY package*.json ./
-
- # Install the dependencies
- RUN npm install
-
- # Copy the rest of the application code to the working directory
- COPY . .
-
- # Start the application
- 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!
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.