For Forntend
- HTML
- JS
For Backend
- Nodejs
- Express
- Google cloud App Engine
- CLoud-MySQl
Step 1: create a new directory
$ mkdir node-app
Step 2: Initialize your Directory using
$ npm init
Step 3: Install node Modules and some Important modules like express,mysql,body-parser,dotenv
$ npm i node-modules express mysql body-parser dotenv path
Step 4: now make a app.js
$ touch app.js
**Step 5: copy this code **
const express = require('express')
const app = express();
app.get('/',(req,res)=>{
res.send("its working");
res.end();
})
app.listen(8080,()=>{
console.log('app is listen on port number 8080');
});
**Step 5: Lets test the previous steps **
npm app.js
Step 6: make views directory which contains all the view pages like: index.html in our case. Make index.html file in views directory and make a simple form in index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="upload" method="POST">
<label for="name">Name</label>
<input type="text" id="name" name="name">
<label for="email">Email</label>
<input type="text" id="email" name="email">
<input type="submit">
</form>
</body>
</html>
Step 7: To make app.js send index.html on user requesting '/' and response to '/upload' req. we have make some change in app.js
const express = require('express')
const app = express();
// For path
const path = require('path');
// Decodes post data
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended:'false'}));
// Get req handler
app.get('/',(req,res)=>{
res.sendFile(path.join(__dirname+'/views/index.html'));
})
// Post req handler
app.post('/upload',(req,res)=>{
let data = req.body;
console.log(data);
res.send('its working till step 7 you did a great job');
});
app.listen(8080,()=>{
console.log('app is listen on port number 8080');
});
node app
Step 8: Next step is Deployment of you App. For this purpose Iam using Google cloud app Engine. Make your Account and setup billing. Then make project in https://console.cloud.google.com/. Go to app engine dashboard create app engine instance and setup gcloud in your local machine. Create app.yaml file which specifies the app engine runtime. let deploy app using
$ gcloud app deploy
Use this to locate your App
$ gcloud app browse
**Step 9: Lets Connect App with Database. Here Iam using Gcloud My-sql database. go to sql dashboard create a instance . I recommend to use this link->https://cloud.google.com/sql/docs/mysql/quickstart. AND use use this link->https://cloud.google.com/sql/docs/mysql/quickstart-proxy-test to connect gcloud sql database to localmachine for local testing **
Step 10: Create Database.js and make some changes in app.js
Step 11: Change YOUR_CONNECTION and other details with your instances details.
run app via node start.
##THANK YOU SO MUCH