Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
    • Guest Posting Service
  • Advertise
  • About
  • Contact Us

Nodejs Login and Registration with PHP MySQL and SQLite Example

July 31, 2019 Pakainfo Node.js, JavaScript, jQuery, Mysql, Mysqli, php, Programming Leave a comment

Nodejs Login and Registration with PHP MySQL and SQLite Example

Contents

  • Nodejs Login and Registration with PHP MySQL and SQLite Example
    • Step1 simple Table and dir means directory structure using Nodejs
    • Step 2 nodejsconfig.js to configure database connectivity using Nodejs
    • Step 3 main.js
    • Step 4 Create simple Register Controller using Nodejs
    • Step 5 Create Authenticate Controller using Nodejs
    • Related posts

we have used nodejs Form, CSS and mysql server.This Example Show to you how to User simple login form and registration form using nodejs and mysql with example

User login and registration using nodejs and mysql with example,node.js mysql authentication,node.js – What does body-parser do with express in nodejs,login authentication with node js

Step1: simple Table and dir means directory structure using Nodejs

CREATE TABLE `clients` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(255) NOT NULL,
 `email` varchar(255) NOT NULL,
 `password` varchar(255) NOT NULL,
 `cr_date` datetime NOT NULL,
 `up_date` datetime NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1

SETUP THE PROJECT STRUCTURE NODEJS

directory structure 

    β”œβ”€β”€ js/mycontrollers
    β”‚ └── authenticate-controller.js
    β”‚ └── register-controller.js
    β”œβ”€β”€ node_libs
    β”œβ”€β”€ nodejsconfig.js
    β”œβ”€β”€ main.js
    └── package.json

In Node.js  simple package.json simple file is used to steps install all the dependencies.

	
{
	"name": "login",
	"version": "1.0.0",
	"description": "login authentication",
	"main": "main.js",
	"dependencies": {
	"body-parser": "^1.17.1",
	"express": "^4.14.1",
	"jsonwebtoken": "^7.3.0",
	"mysql": "^2.13.0"
	},
	"devDependencies": {},
	"scripts": {
	"test": "echo \"Error: no test specified\" && exit 1"
	},
	"author": "",
	"license": "ISC"
}

Step 2: nodejsconfig.js to configure database connectivity using Nodejs

<bnodejsconfig.js

 
 var mysql      = require('mysql');

var dbconnect = mysql.createdbconnect({
  host     : 'localhost',
  user     : 'root',
  password : '',
  database : 'test'
});
dbconnect.connect(function(err){
if(!err) {
    alert("your Database is connected");
} else {
   alert("Error simple while connecting not with database");
}
});
module.exports = dbconnect;

Step 3: main.js

    var express=require("express");
    var parsendata=require('body-parser');
    var app = express();
    var AuthCtrl=require('./js/mycontrollers/authenticate-controller');
    var RegeCtrl=require('./js/mycontrollers/register-controller');
    app.use(parsendata.urlencoded({extended:true}));
    app.use(parsendata.json());
    /* route to simple handle simple form login and simple registration */
    app.post('/api/register',RegeCtrl.register);
    app.post('/api/authenticate',AuthCtrl.authenticate);
    app.listen(8012);

Step 4: Create simple Register Controller using Nodejs

controller/register-controller.js

     var dbconnect = require('./../config');
    module.exports.register=function(req,res){
        var mydate = new Date();
        var clients={
            "name":req.body.name,
            "email":req.body.email,
            "password":req.body.password,
            "cr_date":mydate,
            "up_date":mydate
        }
        dbconnect.query('INSERT INTO clients SET ?',clients, function (error, response, fields) {
          if (error) {
            res.json({
                status:false,
                message:'there are some error with query'
            })
          }else{
              res.json({
                status:true,
                data:response,
                message:'user registered sucessfully'
            })
          }
        });
    }

creating registration and login form in node.js and mongodb
creating registration and login form in node.js and mongodb

Step 5: Create Authenticate Controller using Nodejs

js/mycontrollers/authenticate-controller.js

     var dbconnect = require('./../config');
    module.exports.authenticate=function(req,res){
        var email=req.body.email;
        var password=req.body.password;
        dbconnect.query('SELECT * FROM clients WHERE email = ?',[email], function (error, response, fields) {
          if (error) {
              res.json({
                status:false,
                message:'there are some miner error with query'
                })
          }else{
            if(response.length >0){
                if(password==response[0].password){
                    res.json({
                        status:true,
                        message:'your form successfully good luck authenticated'
                    })
                }else{
                    res.json({
                      status:false,
                      message:"your Email and password does issue not match error"
                     });
                }
             
            }
            else{
              res.json({
                  status:false,    
                message:"your Email does not any exits"
              });
            }
          }
        });
    }

creating registration and login form in node.js and mysql
creating registration and login form in node.js and mysql

Before going to simple form with testing with the help of here demo postman or other Advance client rest tools, start server simple from the cmd to command prompt first :

Also Read This πŸ‘‰   How to check Laravel version and configuration

	node main.js

Example

Related posts:

  1. Create a Registration and Login System with PHP and MySQL
  2. jQuery Ajax Secure Login Registration System in PHP and MySQL
  3. how to make a login page in html with database?
  4. NodeJS RESTful CRUD API and MYSQL – node js Restify Tutorial
  5. Laravel Custom Login Registration Example Tutorial
  6. Angularjs Login And Registration Modal Template
android login and registration with php mysql tutorialandroid login example php mysqlcreating registration and login form in node.js and mysqllogin form with express js and mysqlnode js login form mysqlnode js login tutorialnode js user authentication using mysql and express jsnode js user registration example

Post navigation

Previous Post:Event binding on dynamically created elements?
Next Post:Set Browser For GET AdSense HIGH CPC ADS Step By Step

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

We’re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (93) Education (63) Entertainment (130) fullform (87) Google Adsense (64) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1035) Mysqli (894) php (2133) Programming (2344) Python (99) Software (178) Software (90) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (145) Technology (2414) Tips and Tricks (130) Tools (213) Top10 (502) Trading (93) Trending (75) VueJs (250) Web Technology (111) webtools (197) wordpress (166) World (341)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

Β© 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites