1---
2title: Build lifecycle hooks
3description: Learn how to use the EAS Build lifecycle hooks with npm to customize your build process.
4---
5
6There are five EAS Build lifecycle npm hooks that you can set in your **package.json**. See the [Android build process](android-builds.mdx) and [iOS build process](ios-builds.mdx) docs to get a better understanding about the internals of the build process.
7
8- `eas-build-pre-install` - executed before EAS Build runs `npm install`.
9- `eas-build-post-install` - the behavior depends on the platform and project type:
10  - Android - runs once after the following commands have all completed: `npm install` and `npx expo prebuild` (if needed)
11  - iOS - runs once after the following commands have all completed: `npm install`, `npx expo prebuild` (if needed), and `pod install`.
12- `eas-build-on-success` - this hook is triggered at the end of the build process if the build was successful.
13- `eas-build-on-error` - this hook is triggered at the end of the build process if the build failed.
14- `eas-build-on-complete` - this hook is triggered at the end of the build process. You can check the build's status with the `EAS_BUILD_STATUS` environment variable. It's either `finished` or `errored`.
15- `eas-build-on-cancel` - this hook is triggered if the build is canceled.
16
17Below is an example of how your **package.json** can look with lifecycle hooks:
18
19```json package.json
20{
21  "name": "my-app",
22  "scripts": {
23    "eas-build-pre-install": "echo 123",
24    "eas-build-post-install": "echo 456",
25    "eas-build-on-success": "echo 789",
26    "eas-build-on-error": "echo 012",
27    "eas-build-on-cancel": "echo 345",
28    "start": "expo start",
29    "test": "jest"
30  },
31  "dependencies": {
32    "expo": "~46.0.0"
33    // ...
34  }
35}
36```
37
38## Platform-specific hook behavior
39
40If you would like to run a script (or some part of a script) only for iOS builds or only for Android builds, you can fork the behavior depending on the platform within the script. See examples for common ways to do this through a shell script or a Node script below.
41
42## Examples
43
44### `package.json` and shell script
45
46```json package.json
47{
48  "name": "my-app",
49  "scripts": {
50    "eas-build-pre-install": "./pre-install",
51    "start": "expo start"
52    // ...
53  },
54  "dependencies": {
55    // ...
56  }
57}
58```
59
60```bash pre-install
61#!/bin/bash
62
63# This is a file called "pre-install" in the root of the project
64
65if [[ "$EAS_BUILD_PLATFORM" == "android" ]]; then
66  echo "Run commands for Android builds here"
67elif [[ "$EAS_BUILD_PLATFORM" == "ios" ]]; then
68  echo "Run commands for iOS builds here"
69fi
70```
71
72### `package.json` and Node script
73
74```json package.json
75{
76  "name": "my-app",
77  "scripts": {
78    "eas-build-pre-install": "node pre-install.js",
79    "start": "expo start"
80    // ...
81  },
82  "dependencies": {
83    // ...
84  }
85}
86```
87
88```js pre-install.js
89// This is a file called "pre-install.js" in the root of the project
90
91if (process.env.EAS_BUILD_PLATFORM === 'android') {
92  console.log('Run commands for Android builds here');
93} else if (process.env.EAS_BUILD_PLATFORM === 'ios') {
94  console.log('Run commands for iOS builds here');
95}
96```
97