External Environment Setup
Explore setting up the external development environment by installing Node.js version 16 with nvm and scaffolding a TypeScript React application using create-react-app. Understand how to clean up boilerplate files to start with a minimal, ready-to-code project setup.
Environmental Setup
If you are interested in running this course’s code in an external environment, like in Visual Studio Code, this lesson explains what tools are used to test and run all the code in this course.
Node version![]()
We’re going to use Node version 16, since that’s the new, long-term support (LTS) version of Node as of June 2022.
Install nvm
We can use nvm to maintain a variety of node versions on a single machine. To install nvm, let’s open a terminal and issue the following command:
Optionally, we can use this command:
After installing, be sure to check your ~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc, to ensure the following lines are appended:
These lines will load nvm and ensure it is in your environment.
Install Node version 16
Now, with nvm installed, we can install Node version 16:
Omitting the minor and patch versions will tell nvm to install the latest version within the major 16th version.
If all goes well, something like this should appear in the terminal:
Additionally (and optionally), we can alias this to the default nvm version.
Every time a terminal starts, nvm will use this as the default.
Scaffold the app with create-react-app
We’ll begin scaffolding our application by using create-react-app with its TypeScript template.
When create-react-app is done scaffolding, we can cd into the folder it creates and open it in a code editor. Visual Studio Code is one of the most commonly used code editors for TypeScript. It installs with the shell command code. Like TypeScript, Visual Studio Code is part of the Microsoft ecosystem, and many developers use it. We open the code in Visual Studio Code with the command below:
Remove additional fluff
Let’s remove the extraneous materials that create-react-app adds to this app. First, in the src/ folder, delete the following files:
App.cssApp.test.tsxindex.csslogo.svgsetupTests.ts
We can also delete the boilerplate text that create-react-app puts in README.md and add the following instead:
Then, we’ll remove the CSS import from index.tsx.
We should also remove the logo and CSS imports from App.tsx.
Finally, we clean up the render function to return Hello World!. In the end, our App.tsx looks like this:
Run the application
To make sure all our changes were correct, we can start the React application with the following command in the project root directory:
If everything worked, we should see the following output in our terminal as well as some additional
At this point, our application should render just a simple, Hello World! with no styling.
View the example app
We can run an example app with everything we’ve done so far here:
# educative-advanced-typescript-generic-search-sorting-filtering The code for the course on Educative, "Advanced TypeScript: Generic Search, Sorting, and Filtering"!
Conclusion
In this lesson, we installed nvm and Node v16 to ensure that we have the correct environment for these lessons. Then, we scaffolded a React application using create-react-app and its Typescript template. Finally, we removed unneeded files from the template so we had a clean slate to start with. All the code and interactive code examples in this course are based on this type of blank-slate TypeScript and React environment.