When following a tutorial and starting to learn to develop websites with NodeJS one command I learned installed with NodeJS, was the npx command. You can use it to download the latest version of supporting software you wish to install. Sometimes instructions I’ve been given in the past have advised the following:
To start working on your new react app, invoke the create-react-app command, using npx create-react-app my-app-name.
When you use npx this way, the command attempts to download the latest version of the create-react-app tool if it is not already installed in your NPM development environment.
You may run into situations where you need the create-react-app command to create a project using a specific version of React. If you’re following a tutorial, you may need a specific version installed to get things going for yourself. Instead, we can use the npm init command, and point specifically to a set of scripts we will use to accompany what we feel comfortable using when we first start out.
Here is a method to replace a React development project, with React version 16, a version that from my experience, works well with many tutorials I have found in courses on UDemy. I will use terminal commands like the following to demonstrate
> My command-line terminal commands look like this.
1: Create a folder for your project.
My project is called “myproject”. So I will create a folder: myproject
> mkdir myproject
2. Set up scaffolding and react scripts
… inside project folder
> cd myproject
> npm init react-app . --scripts-version 3.0.1
The NPM init script is shorthand for the command “npm create-react-app” (not npx!), but the nice thing is we’re allowed to append special parameters like the version of react scripts we wish to install. Be sure to include the . to specify that you want the application to be created in the then current working directory (inside myproject).
Note: Different react scripts control what files you will see in the initialized React application. Version 3.0.1 contains a serviceWorker.js file, for instance.
3. Remove node_modules from your project
… after the init command finishes.
node_modules will contain elements unnecessary to the development of your app after the next few steps are completed, and will get in the way of installing the correct version of the app. It could take some time to perform this operation.
I’d recommend sending it to the Recycle Bin using a filesystem explorer, like Windows Explorer, or Apple Finder, or Nautilus, so that you can view progress of commands like this. We’re ready to finish the task
4. Install the react version you want in your project
> npm install --save react@16.8.6 # to install react version 16.8.6
> npm install --save react-dom^16.8.6 # to install react-dom at least 16.8.6
Running these two commands (use the text before the #’s) installs the two react packages that work together to support a basic React app. I chose to install react version 16.8.6, and react-dom version at least 16.8.6.
Good to go. You’re ready to begin development.
You can now install all the other packages that help you develop good apps.