Running a custom build step Stay organized with collections Save and categorize content based on your preferences.
By default, the node.js runtime will executenpm run build if abuild scriptis detected inpackage.json file. If you require additional control over your buildsteps before starting your application, you can provide a custom buildstep. Custom build steps can be executed by addinggcp-build in yourpackage.json file.
To prevent your build from running thenpm run build script, you must either:
- Add a
gcp-buildscript with an empty value in yourpackage.jsonfile:"gcp-build":"". For details about configuring thepackage.json, seeNode.js buildpacks configurations. Add the
GOOGLE_NODE_RUN_SCRIPTSbuild environment variable with an empty value in yourapp.yamlfile.build_env_variables:GOOGLE_NODE_RUN_SCRIPTS:''
build_env_variables section in theapp.yaml file.When this script is executed, the dependencies in thedependencies anddevDependencies fields of yourpackage.json file are available.After executing your custom build step, App Engine removes and regenerates thenode_modules folder by only installing the production dependencies declaredin thedependencies field of yourpackage.json file.
For more information on how to configure the runtime for custom build steps,seeExecuting custom build steps during deploymentfor Node.js buildpacks.
Example
A custom build script can be used for pre-processing tasks, such aspre-processing CSS, minifying client side JavaScript, or running tools, such aswebpack orgulp.
For example, to compile TypeScript to JavaScript, yourpackage.json file mightlook like the following. Note thegcp-build script:
{"name":"appengine-typescript","description":"An example TypeScript app running on Google App Engine.","version":"0.0.1","private":true,"license":"Apache Version 2.0","author":"Google Inc.","engines":{"node":"20.x"},"scripts":{"prepare":"npm run gcp-build","pretest":"npm run gcp-build","test":"c8 mocha -p -j 2 test/*.test.js --exit","lint":"gts lint","start":"node ./index.js","deploy":"gcloud app deploy","clean":"gts clean","compile":"tsc -p .","fix":"gts fix","build":"tsc -p .","gcp-build":"tsc -p ."},"dependencies":{"@typescript-eslint/parser":"^8.0.0","express":"^4.16.3"},"devDependencies":{"@types/express":"^4.17.17","@types/node":"^20.0.0","c8":"^10.0.0","chai":"^4.5.0","gts":"^5.0.0","mocha":"^10.2.0","typescript":"^5.0.0","wait-port":"^1.0.0"}}Serving static files
When you generate or copy files during the custom build step, App Engine doesnot serve these static files directly from your app using either thestatic_dirorstatic_fileselements defined in theapp.yaml file. Instead, App Engine uploadsthe static files to the serving infrastructure in the standard environmentbefore running the custom build step. Any request to the files generated orcopied during the custom build step results in a404 NOT FOUNDHTTP error.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-15 UTC.