Exécuter localement avec le framework des fonctions
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Cette page explique comment installer et exécuter des frameworks de fonctions pour le développement local.
Avant de commencer
Si vous utilisez pour la première fois des fonctions Cloud Run avec Cloud Code, consultez le guide de démarrage rapide Premiers pas avec les fonctions Cloud Run. Une fois que vous avez créé et déployé une fonction à l'aide d'un exemple de code Cloud, vous pouvez revenir à ce guide pour configurer un environnement de développement local.
Installer et exécuter le framework des fonctions localement
Pour installer et exécuter le framework des fonctions en local, procédez comme suit:
Dans Cloud Shell, cliquez sur Cloud Code, puis développez l'explorateur Cloud Functions.
Développez votre projet Google Cloud , effectuez un clic droit sur la fonction déployée de votre choix, puis sélectionnez Télécharger dans un nouvel espace de travail. Cette opération télécharge le code source de votre fonction depuis Google Cloud vers votre ordinateur local et crée un nouvel espace de travail dans votre IDE.
Cliquez sur Terminal > Nouveau terminal pour ouvrir le terminal dans Cloud Shell.
Pour installer les dépendances locales dans le dossier local de votre fonction, accédez au dossier local de votre fonction dans le terminal, puis exécutez la commande suivante:
Node.js
npminstall
Python
pipinstallfunctions-framework
Pour exécuter le framework des fonctions local, exécutez la commande suivante:
Node.js
npxfunctions-framework--target=entryPoint
Python
functions-framework--target=entryPoint
Pour trouver le entryPoint de votre fonction, ouvrez votre fichier launch.json et recherchez la valeur attribuée à entryPoint.
Par exemple, si vous utilisez l'application exemple Hello World de Cloud Code, la configuration s'affiche comme suit:
"entryPoint": "helloHttp",
Pour tester votre fonction, lorsque vous y êtes invité, cliquez sur Ouvrir dans le navigateur ou sur + Nouveau terminal, puis exécutez la commande suivante:
curl http://localhost:8080/
Le contexte de la fonction s'affiche dans le terminal.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/09/04 (UTC)."],[[["\u003cp\u003eThis page guides you through installing and running Functions Framework locally for development purposes.\u003c/p\u003e\n"],["\u003cp\u003eBefore getting started, it's recommended to have previously deployed a Cloud Run function using a Cloud Code sample.\u003c/p\u003e\n"],["\u003cp\u003eInstallation involves downloading your function's source code to your local machine and installing the necessary dependencies using \u003ccode\u003enpm install\u003c/code\u003e (for Node.js) or \u003ccode\u003epip install functions-framework\u003c/code\u003e (for Python).\u003c/p\u003e\n"],["\u003cp\u003eYou can run Functions Framework locally using \u003ccode\u003enpx functions-framework --target=entryPoint\u003c/code\u003e (Node.js) or \u003ccode\u003efunctions-framework --target=entryPoint\u003c/code\u003e (Python), with the \u003ccode\u003eentryPoint\u003c/code\u003e specified in your \u003ccode\u003elaunch.json\u003c/code\u003e file.\u003c/p\u003e\n"],["\u003cp\u003eAfter running Functions Framework locally, you can test your function by opening it in a browser, or using \u003ccode\u003ecurl http://localhost:8080/\u003c/code\u003e in a new terminal.\u003c/p\u003e\n"]]],[],null,["# Run locally with Functions Framework\n\nThis page shows you how to install and run\n[Functions Frameworks](/functions/docs/functions-framework) for local\ndevelopment.\n\nBefore you begin\n----------------\n\nIf this is your first time using [Cloud Run functions](/run/docs/functions-with-run)\nwith Cloud Code, see the\n[Get started with Cloud Run functions](/functions/docs/get-started-in-cloud-run)\nquickstart. Once you've created and deployed a function using a\nCloud Code sample, you can return to this guide to setup a local\ndevelopment environment.\n\nInstall and run Functions Framework locally\n-------------------------------------------\n\nTo install and run Functions Framework locally, follow these steps:\n\n1. In\n Cloud Shell, click\n\n **Cloud Code** and then expand the **Cloud Functions** explorer.\n\n2. Expand your Google Cloud project, right-click a deployed function of\n your choice, and select **Download to new workspace**. This downloads the source\n code of your function from Google Cloud to your local machine and\n creates a new workspace in your IDE.\n\n3. Click **Terminal** \\\u003e **New Terminal**\n to open the terminal in Cloud Shell.\n\n4. To install the local dependencies to your function's local folder, navigate\n to your function's local folder in the terminal and then run the following:\n\n ### Node.js\n\n npm install\n\n ### Python\n\n pip install functions-framework\n\n5. To run the local Functions Framework, run the following:\n\n ### Node.js\n\n ```bash\n npx functions-framework --target=entryPoint\n ```\n\n ### Python\n\n ```bash\n functions-framework --target=entryPoint\n ```\n\n To find the `entryPoint` of your function, open your `launch.json` file and\n look for the assigned value of `entryPoint`.\n\n For example, if you're using Cloud Code's Hello World sample\n application, the configuration appears as follows: \n\n \"entryPoint\": \"helloHttp\",\n\n6. To test your function, when prompted, click **Open in Browser** , or click\n **+ New Terminal** and run the following:\n\n curl http://localhost:8080/\n\n | **Note:** By default, your function will be accessible at `localhost:8080`.\n\n This shows the context of the function in the terminal.\n\nFor more information on how to call locally running functions, see\n[Local functions development](/run/docs/local-dev-functions)."]]