Monday, July 31, 2017

Create a Reactjs Application

Upgrade Nodejs

The default installed version of Nodjs in Ubuntu 16.04 is 4.x and I could not upgrade it to the latest 6.x from normal update using apt update. So, we need to add sources for nodejs to upgrade to the latest version. We need latest version which functions better and the create-react-app works perfectly.

So, to updgrade, we need to create a new sources list file for nodejs.

  1. Create a new file /etc/apt/sources.list.d/nodesource.list with the following contents: deb xenial main
    deb-src xenial main
  2. Add public key which is needed:
    curl -s | sudo apt-key add -
  3. Update Repository
    sudo apt update
  4. Check
    sudo apt-cache policy nodejs
    You will see which version gonna install
  5. Install
    sudo apt install nodejs  
Create Reactjs Project

After installation of nodejs, now we create a reactjs application. The easiest method is install create-react-app package and start with a new scratch project.

npm install -g create-react-project
create-react-app my-app
cd my-app
npm start

Thats it! Now you can see the running react application in localhost:8000

After the application is ready for deployment, we use the following command to build.

npm run build

This process creates a build directory with all files we need to deploy.

No comments:

Post a Comment