Using Node.js in a Python Environment
Sometimes, a project requires both Python and Node.js. For example, you might have a Python backend (like Django or Flask) that serves a frontend built with a JavaScript framework (like React or Vue), and you want to build both from the same service.
Seenode’s native Python environment does not include Node.js by default. However, you can easily install it during your build process. This guide shows you how.
-
Create a Setup Script
Create a script in your repository to download and install Node.js. This keeps your build command clean and your setup process organized.
Create a file named
install_node.sh
with the following content:install_node.sh #!/bin/bashset -eecho "Installing Node.js and npm..."# Update package lists and install dependenciesapt-get update && apt-get install -y curl# Add Node.js repository and install Node.js (v20)curl -fsSL https://deb.nodesource.com/setup_20.x | bash -apt-get install -y nodejs# Upgrade npm to the latest versionnpm install -g npm@latest# Clean up apt cache to reduce image sizeapt-get clean && rm -rf /var/lib/apt/lists/*echo "Node.js installation complete."node --versionnpm --versionThis script will:
- Install
curl
, a tool for downloading files. - Add the official NodeSource repository for Node.js 20.
- Install Node.js and npm.
- Clean up unnecessary files to keep your service’s image small.
- Install
-
Make the Script Executable
Before you can run the script, you need to make it executable. Run this command locally and commit the change:
Terminal chmod +x install_node.sh -
Update Your Build Command
Now, modify the Build Command in your service’s settings on Seenode to run your new script before installing your Python dependencies.
Terminal ./install_node.sh && pip install -r requirements.txtIf you also need to build your frontend assets, you can add that to the command as well:
Terminal ./install_node.sh && npm install && npm run build && pip install -r requirements.txt
With this setup, every time you deploy your service, Seenode will first install Node.js and then proceed with your regular Python build process.