Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React tutorial - how do I start the node server for a reactJs application?

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

like image 475
Marc Avatar asked Mar 02 '16 21:03

Marc


4 Answers

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.

like image 186
Carl Vitullo Avatar answered Nov 15 '22 01:11

Carl Vitullo


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.
like image 24
w411 3 Avatar answered Nov 14 '22 23:11

w411 3


You can run any one of the below mentioned commands to start the node server for your ReactJS application:

  1. npm run-script start
  2. npm run start
  3. npm 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.

like image 4
RBT Avatar answered Nov 15 '22 00:11

RBT


I used Node to run the server. The steps I followed are:

  1. I downloaded the zip package from the Running a server section here

  2. I had the link open: http://localhost:3000/

  3. 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:

enter image description here

When I refresh the localhost web page I see the following:

enter image description here

like image 3
Gloria Avatar answered Nov 15 '22 01:11

Gloria