GithubHelp home page GithubHelp logo

form-nodejs-gcloud's Introduction

form-nodejs-gcloud

It a simple web application which help in understanding full stack development

For Forntend

  1. HTML
  2. JS

For Backend

  1. Nodejs
  2. Express
  3. Google cloud App Engine
  4. 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

image
image
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

image image
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 image

$ 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 image image
Step 11: Change YOUR_CONNECTION and other details with your instances details.
run app via node start.
##THANK YOU SO MUCH

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.