Skip to content

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.

  1. 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/bash
    set -e
    echo "Installing Node.js and npm..."
    # Update package lists and install dependencies
    apt-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 version
    npm install -g npm@latest
    # Clean up apt cache to reduce image size
    apt-get clean && rm -rf /var/lib/apt/lists/*
    echo "Node.js installation complete."
    node --version
    npm --version

    This 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.
  2. 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
  3. 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.txt

    If 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.