Create a project. A file named package.json
will be created in the root directory.
1 | npm init |
Install express. --save
option will save the dependency in the package.json
file.
1 | npm install express --save |
Check what packages are installed.
1 | npm ls --depth=0 |
Create a file called server.js
in the root directory.
1 | const express = require('express'); |
Create a directory named static
and create a index.html
in that directory.
Run the server.
1 | npm start |
Open the browser and go to localhost:3000
, the index page should be seen.
Create a folder named src
in the root directory, and put the jsx files in it.
babel is deprecated, change it later!!!
Install babel-cli
(the command line tool that invokes the transformation) and babel-preset-react
(the plugin that handles React JSX transformation)
1 | npm install --save-dev babel-cli babel-preset-react babel-preset-es2015 |
Add this in the package.json
file:
1 | { |
Then, we can run it using the command.
1 | npm run compile |
In order to automatically restart the server, install the package nodemon
1 | npm install nodemon --save-dev |
Modify the code in package.json
.
1 | { |
-w
specifies which files to watch for changes. The server restarts only when the back-end files are changed.
Use body-parser
to parse various types of request bodies including URL Encoded form data and JSON.
1 | npm install body-parser --save |
Then, in server.js
, add the code below:
1 | const bodyParser = require('body-parser'); |
React
…