I'm just starting the react.js tutorial, I've downloaded the files and then it mentions:
"Follow your progress by opening http://localhost:3000 in your browser (after starting the server). "
I know this may sound stupid, (bear with me since I'm a beginner with React) but how do I start the server in this instance?
Thanks.
Marc
Pretty solid chance it's npm start
from the project root.
Properly packaged modules will have some node scripts configured in package.json
. It's customary to use start
as the script to run the dev environment, though some might use build
, dev
, or other names.
Here's official installation process: link, and officially recommended tutorials
# install react cli
npm install -g create-react-app
# create app
create-react-app my-react-app-name
# go to project folder
cd my-react-app-name
# install dependencies
npm install
# start live server
npm start
output:
$ You can now view my-react-app-name in the browser.
$ Local: http://localhost:3000/
$ On Your Network: http://192.168.0.105:3000/
$ Note that the development build is not optimized.
$ To create a production build, use npm build.
You can run any one of the below mentioned commands to start the node server for your ReactJS application:
start
start
start
All the above commands are equivalent but people prefer the third one as it is the shortest to type on keyboard.
The start
parameter in these commands maps to the start
key present under scripts
configuration present in package.json
file of any ReactJS application. Here is a sample package.json
file of my hello-world application:
{
"name": "hello-world",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.4.2",
"react-dom": "^15.4.2"
},
"devDependencies": {
"react-scripts": "0.9.5"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
You can see that react-scripts start
is written in front of start
key. So react-scripts start
command will get fired when we run npm start
command on console.
I used Node to run the server. The steps I followed are:
I downloaded the zip package from the Running a server section here
I had the link open: http://localhost:3000/
I opened up Node.js Command Prompt and navigated to the downloaded zip project. From Node example here:
Just type the commands in the example: First npm install and then node server.js.
See the screen shot below:
When I refresh the localhost web page I see the following:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With