Back-End
create a "back" directory:
mkdir back
cd backinitialize an npm project in it:
npm initLet's install a few modules that we'll need:
npm install --save @babel/cli @babel/core @babel/node @babel/preset-env @babel/register nodemon rimraf@babel/x: transforms ES6 to ES5, which Node can readnodemon: resets the app every time we save a filerimraf: cross-platform tool to remove directories
Add the following to package.json:
// back/package.json
{
...
"babel": {
"presets": [
"@babel/preset-env"
]
},
"scripts":{
"start": "nodemon --exec babel-node ./src/index.js",
"build:clean":"rimraf ./build",
"build:build": "babel src --out-dir ./build --source-maps",
"build": "npm run build:clean && npm run build:build",
"production": "node ./build/index.js"
},
...
}We just added the scripts:
start: will start the application, and re-run it every time we save a filebuild:clean: will remove generated files in the./builddirectorybuild:build: compiles ES6 to ES5 in the./builddirectorybuild: does both things aboveserve: runs the generated, production-ready, ES5 files
The "babel" key has the Babel configuration.
Then create a directory src and write in it a file called index.js
Open index.js and put:
Run it:
Open your browser on http://localhost:8080. You should see "Hello". You can press ctrl+c in your terminal to stop the server.
At this point, if you want to commit, you'll commit everything in node_modules.
We can avoid this with a .gitignore file. We have one ready, created for us by create-react-app.
Move front/.gitignore to the root, so it applies to our whole project
We're just going to make a few changes in it. Change the line
to
This makes it ignore any directory called node_modules, wherever it is (it previously only worked on directories exactly one node deep).
Also, change /build to **/*build
Last updated
Was this helpful?