-->
Visual Studio allows you to easily create a Node.js project and experience IntelliSense and other built-in features that support Node.js. In this tutorial for Visual Studio, you create a Node.js web application project from a Visual Studio template. Then, you create a simple app using React.
Apr 07, 2020 Download Create React App for free. Set up a modern web app by running one command. Create React App lets you create React apps quickly and easily- no learning of build tools or build configurations necessary. All you need is one command, and you can get started in seconds.
In this tutorial, you learn how to:
Here's a quick FAQ to introduce you to some key concepts.
Node.js is a server-side JavaScript runtime environment that executes JavaScript server-side.
npm is the default package manager for the Node.js. The package manager makes it easier for programmers to publish and share source code of Node.js libraries and is designed to simplify installation, updating, and uninstallation of libraries.
React is a front-end framework to create a UI.
JSX is a JavaScript syntax extension, typically used with React to describe UI elements. JSX code must be transpiled to plain JavaScript before it can run in a browser.
webpack bundles JavaScript files so they can run in a browser. It can also transform or package other resources and assets. It is often used to specify a compiler, such as Babel or TypeScript, to transpile JSX or TypeScript code to plain JavaScript.
You must have Visual Studio installed and the Node.js development workload.
If you haven't already installed Visual Studio 2019, go to the Visual Studio downloads page to install it for free.
If you haven't already installed Visual Studio 2017, go to the Visual Studio downloads page to install it for free.
If you need to install the workload but already have Visual Studio, go to Tools > Get Tools and Features..., which opens the Visual Studio Installer. Choose the Node.js development workload, then choose Modify.
You must have the Node.js runtime installed.
This tutorial was tested with version 12.6.2.
If you don't have it installed, we recommend you install the LTS version from the Node.js website for best compatibility with outside frameworks and libraries. Node.js is built for 32-bit and 64-bit architectures. The Node.js tools in Visual Studio, included in the Node.js workload, support both versions. Only one is required and the Node.js installer only supports one being installed at a time.
In general, Visual Studio automatically detects the installed Node.js runtime. If it does not detect an installed runtime, you can configure your project to reference the installed runtime in the properties page (after you create a project, right-click the project node, choose Properties, and set the Node.exe path). You can use a global installation of Node.js or you can specify the path to a local interpreter in each of your Node.js projects.
First, create a Node.js web application project.
Open Visual Studio.
Create a new project.
Press Esc to close the start window. Type Ctrl + Q to open the search box, type Node.js, then choose Blank Node.js Web Application - JavaScript. (Although this tutorial uses the TypeScript compiler, the steps require that you start with the JavaScript template.)
In the dialog box that appears, choose Create.
From the top menu bar, choose File > New > Project. In the left pane of the New Project dialog box, expand JavaScript, then choose Node.js. In the middle pane, choose Blank Node.js Web Application, type the name NodejsWebAppBlank, then choose OK.
If you don't see the Blank Node.js Web Application project template, you must add the Node.js development workload. For detailed instructions, see the Prerequisites.
Visual Studio creates the new solution and opens your project.
(1) Highlighted in bold is your project, using the name you gave in the New Project dialog box. In the file system, this project is represented by a .njsproj file in your project folder. You can set properties and environment variables associated with the project by right-clicking the project and choosing Properties. You can do round-tripping with other development tools, because the project file does not make custom changes to the Node.js project source.
(2) At the top level is a solution, which by default has the same name as your project. A solution, represented by a .sln file on disk, is a container for one or more related projects.
(3) The npm node shows any installed npm packages. You can right-click the npm node to search for and install npm packages using a dialog box or install and update packages using the settings in package.json and right-click options in the npm node.
(4) package.json is a file used by npm to manage package dependencies and package versions for locally-installed packages. For more information, see Manage npm packages.
(5) Project files such as server.js show up under the project node. server.js is the project startup file and that is why it shows up in bold. You can set the startup file by right-clicking a file in the project and selecting Set as Node.js startup file.
This app requires a number of npm modules to run correctly.
In Solution Explorer (right pane), right-click the npm node in the project and choose Install New npm Packages.
In the Install New npm Packages dialog box, you can choose to install the most current package version or specify a version. If you choose to install the current version of these packages, but run into unexpected errors later, you may want to install the exact package versions described later in these steps.
In the Install New npm Packages dialog box, search for the react package, and select Install Package to install it.
Select the Output window to see progress on installing the package (select Npm in the Show output from field). When installed, the package appears under the npm node.
The project's package.json file is updated with the new package information including the package version.
Instead of using the UI to search for and add the rest of the packages one at a time, paste the following code into package.json. To do this, add a dependencies
section with this code:
If there is already a dependencies
section in your version of the blank template, just replace it with the preceding JSON code. For more information on use of this file, see package.json configuration.
Save the changes.
Right-click npm node in your project and choose Install npm Packages.
This command runs the npm install command directly.
In the lower pane, select the Output window to see progress on installing the packages. Installation may take a few minutes and you may not see results immediately. To see the output, make sure that you select Npm in the Show output from field in the Output window.
Here are the npm modules as they appear in Solution Explorer after they are installed.
Note
If you prefer to install npm packages using the command line, right-click the project node and choose Open Command Prompt Here. Use standard Node.js commands to install packages.
In these steps, you add four new files to your project.
For this simple app, you add the new project files in the project root. (In most apps, you typically add the files to subfolders and adjust relative path references accordingly.)
In Solution Explorer, right-click the project NodejsWebAppBlank and choose Add > New Item.
In the Add New Item dialog box, choose TypeScript JSX file, type the name app.tsx, and select Add or OK.
Repeat these steps to add webpack-config.js. Instead of a TypeScript JSX file, choose JavaScript file.
Repeat the same steps to add index.html to the project. Instead of a JavaScript file, choose HTML file.
Repeat the same steps to add tsconfig.json to the project. Instead of a JavaScript file, choose TypeScript JSON Configuration file.
Open server.js and replace the existing code with the following code:
The preceding code uses Express to start Node.js as your web application server. This code sets the port to the port number configured in the project properties (by default, the port is configured to 1337 in the properties). To open the project properties, right-click the project in Solution Explorer and choose Properties.
Open app.tsx and add the following code:
The preceding code uses JSX syntax and React to display a simple message.
Open index.html and replace the body section with the following code:
This HTML page loads app-bundle.js, which contains the JSX and React code transpiled to plain JavaScript. Currently, app-bundle.js is an empty file. In the next section, you configure options to transpile the code.
In the previous steps, you added webpack-config.js to the project. Next, you add webpack configuration code. You will add a simple webpack configuration that specifies an input file (app.tsx) and an output file (app-bundle.js) for bundling and transpiling JSX to plain JavaScript. For transpiling, you also configure some TypeScript compiler options. This code is a basic configuration that is intended as an introduction to webpack and the TypeScript compiler.
In Solution Explorer, open webpack-config.js and add the following code.
The webpack configuration code instructs webpack to use the TypeScript loader to transpile the JSX.
Open tsconfig.json and replace the default code with the following code, which specifies the TypeScript compiler options:
app.tsx is specified as the source file.
In Solution Explorer, right-click the project node and choose Open Command Prompt Here.
In the command prompt, type the following command:
node_modules.binwebpack app.tsx --config webpack-config.js
The command prompt window shows the result.
If you see any errors instead of the preceding output, you must resolve them before your app will work. If your npm package versions are different than the versions shown in this tutorial, that can be a source of errors. One way to fix errors is to use the exact versions shown in the earlier steps. Also, if one or more of these package versions has been deprecated and results in an error, you may need to install a more recent version to fix errors. For information on using package.json to control npm package versions, see package.json configuration.
In Solution Explorer, right-click the project node and choose Add > Existing Folder, then choose the dist folder and choose Select Folder.
Visual Studio adds the dist folder to the project, which contains app-bundle.js and app-bundle.js.map.
Open app-bundle.js to see the transpiled JavaScript code.
If prompted to reload externally modified files, select Yes to All.
Each time you make changes to app.tsx, you must rerun the webpack command. To automate this step, add a build script to transpile the JSX.
Starting in Visual Studio 2019, a build script is required. Instead of transpiling JSX at the command line (as shown in the preceding section), you can transpile JSX when building from Visual Studio.
Open package.json and add the following section after the dependencies
section:
Select either Web Server (Google Chrome) or Web Server (Microsoft Edge) as the current debug target.
If Chrome is available on your machine, but does not show up as an option, choose Browse With from the debug target dropdown list, and select Chrome as the default browser target (choose Set as Default).
To run the app, press F5 (Debug > Start Debugging) or the green arrow button.
A Node.js console window opens that shows the port on which the debugger is listening.
Visual Studio starts the app by launching the startup file, server.js.
Close the browser window.
Close the console window.
In server.js, click in the gutter to the left of the staticPath
declaration to set a breakpoint:
Breakpoints are the most basic and essential feature of reliable debugging. A breakpoint indicates where Visual Studio should suspend your running code so you can take a look at the values of variables, or the behavior of memory, or whether or not a branch of code is getting run.
To run the app, press F5 (Debug > Start Debugging).
The debugger pauses at the breakpoint you set (the current statement is marked in yellow). Now, you can inspect your app state by hovering over variables that are currently in scope, using debugger windows like the Locals and Watch windows.
Press F5 to continue the app.
If you want to use the Chrome Developer Tools or F12 Tools for Microsoft Edge, press F12. You can use these tools to examine the DOM and interact with the app using the JavaScript Console.
Close the web browser and the console.
In the preceding section, you attached the debugger to server-side Node.js code. To attach the debugger from Visual Studio and hit breakpoints in client-side React code, the debugger needs help to identify the correct process. Here is one way to enable this.
For this scenario, use either Microsoft Edge (Chromium), currently named Microsoft Edge Beta in the IDE, or Chrome.
Close all windows for the target browser.
Other browser instances can prevent the browser from opening with debugging enabled. (Browser extensions may be running and preventing full debug mode, so you may need to open Task Manager to find unexpected instances of Chrome.)
For Microsoft Edge (Chromium), also shut down all instances of Chrome. Because both browsers share the chromium code base, this gives the best results.
Start your browser with debugging enabled.
Starting in Visual Studio 2019, you can set the --remote-debugging-port=9222
flag at browser launch by selecting Browse With... > from the Debug toolbar, then choosing Add, and then setting the flag in the Arguments field. Use a different friendly name for the browser such as Edge with Debugging or Chrome with Debugging. For details, see the Release Notes.
Alternatively, open the Run command from the Windows Start button (right-click and choose Run), and enter the following command:
msedge --remote-debugging-port=9222
or,
chrome.exe --remote-debugging-port=9222
Open the Run command from the Windows Start button (right-click and choose Run), and enter the following command:
chrome.exe --remote-debugging-port=9222
This starts your browser with debugging enabled.
The app is not yet running, so you get an empty browser page.
Switch to Visual Studio and then set a breakpoint in your source code, either app-bundle.js or app.tsx.
For app-bundle.js, set the breakpoint in the render()
function as shown in the following illustration:
To find the render()
function in the transpiled app-bundle.js file, use Ctrl+F (Edit > Find and Replace > Quick Find).
For app.tsx, set the breakpoint inside the render()
function, on the return
statement.
If you are setting the breakpoint in the .tsx file (rather than app-bundle.js), you need to update webpack-config.js. Replace the following code:
with this code:
This is a development-only setting to enable debugging in Visual Studio. This setting allows you to override the generated references in the source map file, app-bundle.js.map, when building the app. By default, webpack references in the source map file include the webpack:/// prefix, which prevents Visual Studio from finding the source file, app.tsx. Specifically, when you make this change, the reference to the source file, app.tsx, gets changed from webpack:///./app.tsx to ./app.tsx, which enables debugging.
Select your target browser as the debug target in Visual Studio, then press Ctrl+F5 (Debug > Start Without Debugging) to run the app in the browser.
If you created a browser configuration with a friendly name, choose that as your debug target.
The app opens in a new browser tab.
Choose Debug > Attach to Process.
Tip
Starting in Visual Studio 2017, once you attach to the process the first time by following these steps, you can quickly reattach to the same process by choosing Debug > Reattach to Process.
In the Attach to Process dialog box, get a filtered list of browser instances that you can attach to.
In Visual Studio 2019, choose the correct debugger for your target browser, JavaScript (Chrome) or JavaScript (Microsoft Edge - Chromium) in the Attach to field, type chrome or edge in the filter box to filter the search results.
In Visual Studio 2017, choose Webkit code in the Attach to field, type chrome in the filter box to filter the search results.
Select the browser process with the correct host port (localhost in this example), and select Attach.
The port (1337) may also appear in the Title field to help you select the correct browser instance.
The following example shows how this looks for the Microsoft Edge (Chromium) browser.
You know the debugger has attached correctly when the DOM Explorer and the JavaScript Console open in Visual Studio. These debugging tools are similar to Chrome Developer Tools and F12 Tools for Microsoft Edge.
Tip
If the debugger does not attach and you see the message 'Unable to attach to the process. An operation is not legal in the current state.', use the Task Manager to close all instances of the target browser before starting the browser in debugging mode. Browser extensions may be running and preventing full debug mode.
Because the code with the breakpoint already executed, refresh your browser page to hit the breakpoint.
While paused in the debugger, you can examine your app state by hovering over variables and using debugger windows. You can advance the debugger by stepping through code (F5, F10, and F11). For more information on basic debugging features, see First look at the debugger.
You may hit the breakpoint in either app-bundle.js or its mapped location in app.tsx, depending on which steps you followed previously, along with your environment and browser state. Either way, you can step through code and examine variables.
If you need to break into code in app.tsx and are unable to do it, use Attach to Process as described in the previous steps to attach the debugger. Make sure you that your environment is set up correctly:
You closed all browser instances, including Chrome extensions (using the Task Manager), so that you can run the browser in debug mode. Make sure you start the browser in debug mode.
Make sure that your source map file includes a reference to ./app.tsx and not webpack:///./app.tsx, which prevents the Visual Studio debugger from locating app.tsx.Alternatively, if you need to break into code in app.tsx and are unable to do it, try using the debugger;
statement in app.tsx, or set breakpoints in the Chrome Developer Tools (or F12 Tools for Microsoft Edge) instead.
If you need to break into code in app-bundle.js and are unable to do it, remove the source map file, app-bundle.js.map.
This page will help you install and build your first React Native app. If you already have React Native installed, you can skip ahead to the Tutorial.
If you are new to mobile development, the easiest way to get started is with Expo CLI. Expo is a set of tools built around React Native and, while it has many features, the most relevant feature for us right now is that it can get you writing a React Native app within minutes. You will only need a recent version of Node.js and a phone or emulator. If you'd like to try out React Native directly in your web browser before installing any tools, you can try out Snack.
If you are already familiar with mobile development, you may want to use React Native CLI. It requires Xcode or Android Studio to get started. If you already have one of these tools installed, you should be able to get up and running within a few minutes. If they are not installed, you should expect to spend about an hour installing and configuring them.
Assuming that you have Node 10 LTS or greater installed, you can use npm to install the Expo CLI command line utility:
Then run the following commands to create a new React Native project called 'AwesomeProject':
This will start a development server for you.
Install the Expo client app on your iOS or Android phone and connect to the same wireless network as your computer. On Android, use the Expo app to scan the QR code from your terminal to open your project. On iOS, follow on-screen instructions to get a link.
Now that you have successfully run the app, let's modify it. Open App.js
in your text editor of choice and edit some lines. The application should reload automatically once you save your changes.
Congratulations! You've successfully run and modified your first React Native app.
Expo also has docs you can reference if you have questions specific to the tool. You can also ask for help at Expo forums.
These tools help you get started quickly, but before committing to building your app with Expo CLI, read about the limitations.
If you have a problem with Expo, before creating a new issue, please see if there's an existing issue about it:
If you're curious to learn more about React Native, continue on to the Tutorial.
Expo CLI allows you to run your React Native app on a physical device without setting up a development environment. If you want to run your app on the iOS Simulator or an Android Virtual Device, please refer to the instructions for 'React Native CLI Quickstart' to learn how to install Xcode or set up your Android development environment.
Once you've set these up, you can launch your app on an Android Virtual Device by running npm run android
, or on the iOS Simulator by running npm run ios
(macOS only).
Because you don't build any native code when using Expo to create a project, it's not possible to include custom native modules beyond the React Native APIs and components that are available in the Expo client app.
If you know that you'll eventually need to include your own native code, Expo is still a good way to get started. In that case you'll need to 'eject' eventually to create your own native builds. If you do eject, the 'React Native CLI Quickstart' instructions will be required to continue working on your project.
Expo CLI configures your project to use the most recent React Native version that is supported by the Expo client app. The Expo client app usually gains support for a given React Native version about a week after the React Native version is released as stable. You can check this document to find out what versions are supported.
If you're integrating React Native into an existing project, you'll want to skip Expo CLI and go directly to setting up the native build environment. Select 'React Native CLI Quickstart' above for instructions on configuring a native build environment for React Native.
Follow these instructions if you need to build native code in your project. For example, if you are integrating React Native into an existing application, or if you 'ejected' from Expo, you'll need this section.
The instructions are a bit different depending on your development operating system, and whether you want to start developing for iOS or Android. If you want to develop for both Android and iOS, that's fine - you can pick one to start with, since the setup is a bit different.
A Mac is required to build projects with native code for iOS. You can follow the Quick Start to learn how to build your app using Expo instead.
You will need Node, Watchman, the React Native command line interface, and Xcode.
While you can use any editor of your choice to develop your app, you will need to install Xcode in order to set up the necessary tooling to build your React Native app for iOS.
You will need Node, Watchman, the React Native command line interface, a JDK, and Android Studio.
You will need Node, the React Native command line interface, a JDK, and Android Studio.
You will need Node, the React Native command line interface, Python2, a JDK, and Android Studio.
While you can use any editor of your choice to develop your app, you will need to install Android Studio in order to set up the necessary tooling to build your React Native app for Android.
We recommend installing Node and Watchman using Homebrew. Run the following commands in a Terminal after installing Homebrew:
If you have already installed Node on your system, make sure it is Node 8.3 or newer.
Watchman is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance.
We recommend installing JDK using Homebrew. Run the following commands in a Terminal after installing Homebrew:
If you have already installed JDK on your system, make sure it is JDK 8 or newer.
Follow the installation instructions for your Linux distribution to install Node 8.3 or newer.
We recommend installing Node and Python2 via Chocolatey, a popular package manager for Windows.
React Native also requires a recent version of the Java SE Development Kit (JDK), as well as Python 2. Both can be installed using Chocolatey.
Open an Administrator Command Prompt (right click Command Prompt and select 'Run as Administrator'), then run the following command:
If you have already installed Node on your system, make sure it is Node 8.3 or newer. If you already have a JDK on your system, make sure it is version 8 or newer.
You can find additional installation options on Node's Downloads page.
The easiest way to install Xcode is via the Mac App Store. Installing Xcode will also install the iOS Simulator and all the necessary tools to build your iOS app.
If you have already installed Xcode on your system, make sure it is version 9.4 or newer.
You will also need to install the Xcode Command Line Tools. Open Xcode, then choose 'Preferences...' from the Xcode menu. Go to the Locations panel and install the tools by selecting the most recent version in the Command Line Tools dropdown.
To install a simulator, open Xcode > Preferences... and select the Components tab. Select a simulator with the corresponding version of iOS you wish to use.
CocoaPods is built with Ruby and it will be installable with the default Ruby available on macOS. You can use a Ruby Version manager, however we recommend that you use the standard Ruby available on macOS unless you know what you're doing.
Using the default Ruby install will require you to use sudo
when installing gems. (This is only an issue for the duration of the gem installation, though.)
For more information, please visit CocoaPods Getting Started guide.
React Native requires version 8 of the Java SE Development Kit (JDK). You may download and install OpenJDK from AdoptOpenJDK or your system packager. You may also Download and install Oracle JDK 8 if desired.
Setting up your development environment can be somewhat tedious if you're new to Android development. If you're already familiar with Android development, there are a few things you may need to configure. In either case, please make sure to carefully follow the next few steps.
Download and install Android Studio. Choose a 'Custom' setup when prompted to select an installation type. Make sure the boxes next to all of the following are checked:
Android SDK
Android SDK Platform
Performance (Intel ® HAXM)
(See here for AMD)Android Virtual Device
Android SDK
Android SDK Platform
Android Virtual Device
Then, click 'Next' to install all of these components.
If the checkboxes are grayed out, you will have a chance to install these components later on.
Once setup has finalized and you're presented with the Welcome screen, proceed to the next step.
Android Studio installs the latest Android SDK by default. Building a React Native app with native code, however, requires the Android 9 (Pie)
SDK in particular. Additional Android SDKs can be installed through the SDK Manager in Android Studio.
The SDK Manager can be accessed from the 'Welcome to Android Studio' screen. Click on 'Configure', then select 'SDK Manager'.
The SDK Manager can also be found within the Android Studio 'Preferences' dialog, under Appearance & Behavior → System Settings → Android SDK.
Select the 'SDK Platforms' tab from within the SDK Manager, then check the box next to 'Show Package Details' in the bottom right corner. Look for and expand the Android 9 (Pie)
entry, then make sure the following items are checked:
Android SDK Platform 28
Intel x86 Atom_64 System Image
or Google APIs Intel x86 Atom System Image
Next, select the 'SDK Tools' tab and check the box next to 'Show Package Details' here as well. Look for and expand the 'Android SDK Build-Tools' entry, then make sure that 28.0.3
is selected.
Finally, click 'Apply' to download and install the Android SDK and related build tools.
The React Native tools require some environment variables to be set up in order to build apps with native code.
Add the following lines to your $HOME/.bash_profile
or $HOME/.bashrc
config file:
.bash_profile
is specific to bash
. If you're using another shell, you will need to edit the appropriate shell-specific config file.
Type source $HOME/.bash_profile
to load the config into your current shell. Verify that ANDROID_HOME has been added to your path by running echo $PATH
.
Please make sure you use the correct Android SDK path. You can find the actual location of the SDK in the Android Studio 'Preferences' dialog, under Appearance & Behavior → System Settings → Android SDK.
Open the System pane under System and Security in the Windows Control Panel, then click on Change settings.... Open the Advanced tab and click on Environment Variables.... Click on New... to create a new ANDROID_HOME
user variable that points to the path to your Android SDK:
The SDK is installed, by default, at the following location:
You can find the actual location of the SDK in the Android Studio 'Preferences' dialog, under Appearance & Behavior → System Settings → Android SDK.
Open a new Command Prompt window to ensure the new environment variable is loaded before proceeding to the next step.
Open the System pane under System and Security in the Windows Control Panel, then click on Change settings.... Open the Advanced tab and click on Environment Variables.... Select the Path variable, then click Edit. Click New and add the path to platform-tools to the list.
The default location for this folder is:
Follow the Watchman installation guide to compile and install Watchman from source.
Watchman is a tool by Facebook for watching changes in the filesystem. It is highly recommended you install it for better performance and increased compatibility in certain edge cases (translation: you may be able to get by without installing this, but your mileage may vary; installing this now may save you from a headache later).
React Native has a built-in command line interface. Rather than install and manage a specific version of the CLI globally, we recommend you access the current version at runtime using npx
, which ships with Node.js. With npx react-native <command>
, the current stable version of the CLI will be downloaded and executed at the time the command is run.
If you previously installed a global react-native-cli
package, please remove it as it may cause unexpected issues.
You can use React Native's built-in command line interface to generate a new project. Let's create a new React Native project called 'AwesomeProject':
This is not necessary if you are integrating React Native into an existing application, if you 'ejected' from Expo, or if you're adding iOS support to an existing React Native project (see Platform Specific Code). You can also use a third-party CLI to init your React Native app, such as Ignite CLI.
If you want to start a new project with a specific React Native version, you can use the --version
argument:
You can also start a project with a custom React Native template, like TypeScript, with --template
argument:
If you previously installed a global react-native-cli
package, please remove it as it may cause unexpected issues.
React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using npx
, which ships with Node.js. Let's create a new React Native project called 'AwesomeProject':
This is not necessary if you are integrating React Native into an existing application, if you 'ejected' from Expo, or if you're adding Android support to an existing React Native project (see Platform Specific Code). You can also use a third-party CLI to init your React Native app, such as Ignite CLI.
If you want to start a new project with a specific React Native version, you can use the --version
argument:
You can also start a project with a custom React Native template, like TypeScript, with --template
argument:
You will need an Android device to run your React Native Android app. This can be either a physical Android device, or more commonly, you can use an Android Virtual Device which allows you to emulate an Android device on your computer.
Either way, you will need to prepare the device to run Android apps for development.
If you have a physical Android device, you can use it for development in place of an AVD by plugging it in to your computer using a USB cable and following the instructions here.
If you use Android Studio to open ./AwesomeProject/android
, you can see the list of available Android Virtual Devices (AVDs) by opening the 'AVD Manager' from within Android Studio. Look for an icon that looks like this:
If you have recently installed Android Studio, you will likely need to create a new AVD. Select 'Create Virtual Device...', then pick any Phone from the list and click 'Next', then select the Pie API Level 28 image.
We recommend configuring VM acceleration on your system to improve performance. Once you've followed those instructions, go back to the AVD Manager.
If you don't have HAXM installed, click on 'Install HAXM' or follow these instructions to set it up, then go back to the AVD Manager.
If you don't have HAXM installed, follow these instructions to set it up, then go back to the AVD Manager.
Click 'Next' then 'Finish' to create your AVD. At this point you should be able to click on the green triangle button next to your AVD to launch it, then proceed to the next step.
If you use the Yarn package manager, you can use yarn
instead of npx
when running React Native commands inside an existing project.
Run npx react-native run-ios
inside your React Native project folder:
You should see your new app running in the iOS Simulator shortly.
npx react-native run-ios
is one way to run your app. You can also run it directly from within Xcode.
If you can't get this to work, see the Troubleshooting page.
The above command will automatically run your app on the iOS Simulator by default. If you want to run the app on an actual physical iOS device, please follow the instructions here.
If you use the Yarn package manager, you can use yarn
instead of npx
when running React Native commands inside an existing project.
Run npx react-native run-android
inside your React Native project folder:
If everything is set up correctly, you should see your new app running in your Android emulator shortly.
npx react-native run-android
is one way to run your app - you can also run it directly from within Android Studio.
If you can't get this to work, see the Troubleshooting page.
Now that you have successfully run the app, let's modify it.
App.js
in your text editor of choice and edit some lines.⌘R
in your iOS Simulator to reload the app and see your changes!App.js
in your text editor of choice and edit some lines.R
key twice or select Reload
from the Developer Menu (⌘M
) to see your changes!Now that you have successfully run the app, let's modify it.
App.js
in your text editor of choice and edit some lines.R
key twice or select Reload
from the Developer Menu (Ctrl + M
) to see your changes!Congratulations! You've successfully run and modified your first React Native app.
Congratulations! You've successfully run and modified your first React Native app.
If you're curious to learn more about React Native, continue on to the Tutorial.
If you're curious to learn more about React Native, continue on to the Tutorial.