xref: /expo/docs/pages/modules/get-started.mdx (revision 46db93c3)
1---
2title: Get started
3description: Learn about getting started with Expo modules API.
4---
5
6import { BoxLink } from '~/ui/components/BoxLink';
7import { Terminal } from '~/ui/components/Snippet';
8
9There are two ways to get started with the Expo Module API: you can either initialize a new module from scratch or add the Expo Module API to an existing module. This guide will walk you through creating a new module from scratch, and the [Integrating in an existing library guide](/modules/existing-library) covers the latter case.
10
11## 1. Creating a new module
12
13To create a new Expo module from scratch, run the `create-expo-module` script as shown below.
14The script will ask you a few questions and then generate the native Expo module along with the example app for Android and iOS that uses your new module.
15
16<Terminal cmd={[`$ npx create-expo-module my-module`]} />
17
18## 2. Running the example project
19
20Navigate to the module directory and then open the Android and/or iOS example project by running the following commands:
21
22<Terminal cmd={[`$ cd my-module`, `$ npm run open:android`, `$ npm run open:ios`]} />
23
24Now, you can run the example project on your device or simulator/emulator. When the project compiles and runs, you will see "Hello world! ��" on the screen.
25
26> **Note:** If you're using Windows, you can open the example project by opening the **android** directory in Android Studio, but you cannot open the iOS project files.
27
28## 3. Making a change
29
30### Android
31
32Open up **MyModuleModule.kt** in Android Studio (<kbd>⌘ Cmd</kbd> + <kbd>O</kbd> or <kbd>Ctrl</kbd> + <kbd>O</kbd> and search for **MyModuleModule.kt**). Change the `hello` method to return a different string. For example, you can change it to return `"Hello world! ����"`. Rebuild the app and you should see your change.
33
34### iOS
35
36Open up **MyModuleModule.swift** in Xcode (<kbd>⌘ Cmd</kbd> + <kbd>O</kbd> or <kbd>Ctrl</kbd> + <kbd>O</kbd> and search for **MyModuleModule.swift**). Change the `hello` method to return a different string. For example, you can change it to return `"Hello world! ����"`. Rebuild the app and you should see your change.
37
38## Next steps
39
40Now that you've learned how to initialize a module and make simple changes to it, you can continue to a tutorial or dive right into the API reference.
41
42<BoxLink
43  title="Creating your first native module"
44  description="Create a simple, but complete, native module to interact with Android and iOS preferences APIs."
45  href="/modules/native-module-tutorial"
46/>
47
48<BoxLink
49  title="Module API Reference"
50  description="Outline for the Expo Module API and common patterns like sending events from native code to JavaScript."
51  href="/modules/module-api"
52/>
53