Stay organized with collections
Save and categorize content based on your preferences.
By default, the node.js runtime will execute npm run build if a build script
is detected in package.json file. If you require additional control over your build
steps before starting your application, you can provide a custom build
step. Custom build steps can be executed by adding gcp-build in your
package.json file.
To prevent your build from running the npm run build script, you must either:
Add a gcp-build script with an empty value in your package.json file:
"gcp-build":"". For details about configuring the package.json, see
Node.js buildpacks configurations.
Add the GOOGLE_NODE_RUN_SCRIPTS
build environment variable with an empty value in your app.yaml file.
build_env_variables:GOOGLE_NODE_RUN_SCRIPTS:''
For details about specifying build environment variables see
build_env_variables section in the app.yaml file.
When this script is executed, the dependencies in the dependencies and
devDependencies fields of your package.json file are available.
After executing your custom build step, App Engine removes and regenerates the
node_modules folder by only installing the production dependencies declared
in the dependencies field of your package.json file.
A custom build script can be used for pre-processing tasks, such as
pre-processing CSS, minifying client side JavaScript, or running tools, such as
webpack or gulp.
For example, to compile TypeScript to JavaScript, your package.json file might
look like the following. Note the gcp-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 does
not serve these static files directly from your app using either the
static_dir
or static_files
elements defined in the app.yaml file. Instead, App Engine uploads
the static files to the serving infrastructure in the standard environment
before running the custom build step. Any request to the files generated or
copied during the custom build step results in a 404 NOT FOUND
HTTP error.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eNode.js runtime defaults to executing \u003ccode\u003enpm run build\u003c/code\u003e if a \u003ccode\u003ebuild\u003c/code\u003e script exists in \u003ccode\u003epackage.json\u003c/code\u003e, but you can implement custom build steps.\u003c/p\u003e\n"],["\u003cp\u003eTo define a custom build process, include a \u003ccode\u003egcp-build\u003c/code\u003e script in your \u003ccode\u003epackage.json\u003c/code\u003e file, which will be executed instead of \u003ccode\u003enpm run build\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo bypass the default \u003ccode\u003enpm run build\u003c/code\u003e execution, add an empty \u003ccode\u003egcp-build\u003c/code\u003e script in \u003ccode\u003epackage.json\u003c/code\u003e as \u003ccode\u003e"gcp-build":""\u003c/code\u003e, or use the environment variable \u003ccode\u003eGOOGLE_NODE_RUN_SCRIPTS\u003c/code\u003e with an empty value.\u003c/p\u003e\n"],["\u003cp\u003eDuring custom build steps, dependencies from both \u003ccode\u003edependencies\u003c/code\u003e and \u003ccode\u003edevDependencies\u003c/code\u003e in \u003ccode\u003epackage.json\u003c/code\u003e are available, but afterwards, App Engine only installs production dependencies listed in \u003ccode\u003edependencies\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eStatic files generated or copied during custom build steps are not served directly by App Engine using \u003ccode\u003estatic_dir\u003c/code\u003e or \u003ccode\u003estatic_files\u003c/code\u003e in \u003ccode\u003eapp.yaml\u003c/code\u003e, and accessing them will result in a \u003ccode\u003e404 NOT FOUND\u003c/code\u003e error.\u003c/p\u003e\n"]]],[],null,["# Running a custom build step\n\nBy default, the node.js runtime will execute `npm run build` if a `build` script\nis detected in `package.json` file. If you require additional control over your build\nsteps before starting your application, you can provide a custom build\nstep. Custom build steps can be executed by adding `gcp-build` in your\n`package.json` file.\n\nTo prevent your build from running the `npm run build` script, you must either:\n\n- Add a `gcp-build` script with an empty value in your `package.json` file: `\"gcp-build\":\"\"`. For details about configuring the `package.json`, see [Node.js buildpacks configurations](/appengine/docs/standard/nodejs/running-custom-build-step#example).\n- Add the [`GOOGLE_NODE_RUN_SCRIPTS`](/docs/buildpacks/nodejs#google_node_run_scripts)\n build environment variable with an empty value in your `app.yaml` file.\n\n build_env_variables:\n GOOGLE_NODE_RUN_SCRIPTS: ''\n\nFor details about specifying build environment variables see [`build_env_variables`](/appengine/docs/standard/reference/app-yaml#runtime_and_app_elements) section in the `app.yaml` file.\n\nWhen this script is executed, the dependencies in the `dependencies` and\n`devDependencies` fields of your `package.json` file are available.\nAfter executing your custom build step, App Engine removes and regenerates the\n`node_modules` folder by only installing the production dependencies declared\nin the `dependencies` field of your `package.json` file.\n\nFor more information on how to configure the runtime for custom build steps,\nsee [Executing custom build steps during deployment](/docs/buildpacks/nodejs#executing_custom_build_steps_during_deployment)\nfor Node.js buildpacks.\n\nExample\n-------\n\nA custom build script can be used for pre-processing tasks, such as\npre-processing CSS, minifying client side JavaScript, or running tools, such as\n`webpack` or `gulp`.\n\nFor example, to compile TypeScript to JavaScript, your `package.json` file might\nlook like the following. Note the `gcp-build` script: \n\n {\n \"name\": \"appengine-typescript\",\n \"description\": \"An example TypeScript app running on Google App Engine.\",\n \"version\": \"0.0.1\",\n \"private\": true,\n \"license\": \"Apache Version 2.0\",\n \"author\": \"Google Inc.\",\n \"engines\": {\n \"node\": \"20.x\"\n },\n \"scripts\": {\n \"prepare\": \"npm run gcp-build\",\n \"pretest\": \"npm run gcp-build\",\n \"test\": \"c8 mocha -p -j 2 test/*.test.js --exit\",\n \"lint\": \"gts lint\",\n \"start\": \"node ./index.js\",\n \"deploy\": \"gcloud app deploy\",\n \"clean\": \"gts clean\",\n \"compile\": \"tsc -p .\",\n \"fix\": \"gts fix\",\n \"build\": \"tsc -p .\",\n \"gcp-build\": \"tsc -p .\"\n },\n \"dependencies\": {\n \"@typescript-eslint/parser\": \"^8.0.0\",\n \"express\": \"^4.16.3\"\n },\n \"devDependencies\": {\n \"@types/express\": \"^4.17.17\",\n \"@types/node\": \"^20.0.0\",\n \"c8\": \"^10.0.0\",\n \"chai\": \"^4.5.0\",\n \"gts\": \"^5.0.0\",\n \"mocha\": \"^10.2.0\",\n \"typescript\": \"^5.0.0\",\n \"wait-port\": \"^1.0.0\"\n }\n }\n\nServing static files\n--------------------\n\nWhen you generate or copy files during the custom build step, App Engine does\nnot serve these static files directly from your app using either the\n[`static_dir`](/appengine/docs/standard/reference/app-yaml#handlers_static_dir)\nor [`static_files`](/appengine/docs/standard/reference/app-yaml#handlers_static_files)\nelements defined in the `app.yaml` file. Instead, App Engine uploads\nthe static files to the serving infrastructure in the standard environment\nbefore running the custom build step. Any request to the files generated or\ncopied during the custom build step results in a `404 NOT FOUND`\nHTTP error."]]