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 RESTful API User Authentication with AngularJS using PHP MYSQL

June 27, 2018 Pakainfo Technology, Ajax, AngularJS, JavaScript, Mysql, Mysqli, Node.js, php Leave a comment

NodeJS RESTful API User Authentication with AngularJS using PHP MYSQL

Contents

  • NodeJS RESTful API User Authentication with AngularJS using PHP MYSQL
    • Step1Create Table and Folder structure
    • Step 2 here PHP Config.js to settings database connectivity
    • Step 3 index.js
    • Step 4 Create Register Controller
    • Step 5 Simple Create AngularJS Authenticate Controller
    • Related posts

In this Post We Will Explain About is NodeJS RESTful API User Authentication with AngularJS using PHP MYSQL With Example and Demo.

Welcome on Pakainfo.com – Examples ,The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to User login and registration using nodejs and mysql with example

In this post we will show you Best way to implement Token-Based Authentication With AngularJS & NodeJS, hear for How to RESTful API User Authentication with Node.js and AngularJS with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Step1:Create Table and Folder structure

CREATE TABLE `emploers` (
 `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,
 `updated_at` datetime NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=latin1

Now we will simple have to setup folders structure in following simple way :

β”œβ”€β”€ appctrl
β”‚ └── authenticate-controller.js
β”‚ └── register-controller.js
β”œβ”€β”€ node_modules
β”œβ”€β”€ config.js
β”œβ”€β”€ index.js
└── package.json

In Node.js add or include package.json file is simple used to install here all the dependencies.

{
  "name": "login",
  "version": "1.0.0",
  "description": "login authentication",
  "main": "index.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: here PHP Config.js to settings database connectivity

config.js

var mysql      = require('mysql');
var live_connect = mysql.createConnection({
  host     : 'Pakainfo.com',
  user     : 'livedata',
  password : '[email protected]#$%5558',
  database : 'Datacode'
});
live_connect.connect(function(err){
if(!err) {
    console.log("simple Database is connected");
} else {
    console.log("Error while not connecting with database");
}
});
module.exports = live_connect;

Step 3: index.js

Now here start with simple index.js file that is as well as entry point of the web- application.

Also Read This πŸ‘‰   Everything You Need To Know About proxy server in 2023

index.js

var express=require("express");
var bodyParser=require('body-parser');
var app = express();
var authenticateController=require('./appctrl/authenticate-controller');
var registerController=require('./appctrl/register-controller');
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());


app.post('/api/register',registerController.register);
app.post('/api/authenticate',authenticateController.authenticate);
app.listen(8012);

Step 4: Create Register Controller

controller/register-controller.js

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

Step 5: Simple Create AngularJS Authenticate Controller

appctrl/authenticate-controller.js

var live_connect = require('./../config');
module.exports.authenticate=function(req,res){
    var email=req.body.email;
    var password=req.body.password;
    live_connect.query('SELECT * FROM emploers WHERE email = ?',[email], function (error, results, fields) {
      if (error) {
          res.json({
            status:false,
            message:'Here live24u are some error mistac with query'
            })
      }else{
        if(results.length >0){
            if(password==results[0].password){
                res.json({
                    status:true,
                    message:'Pakainfo.com successfully smple authenticated congo!!'
                })
            }else{
                res.json({
                  status:false,
                  message:"Pakainfo.com your Email Address with password does not match"
                 });
            }
         
        }
        else{
          res.json({
              status:false,    
            message:"Pakainfo.com Email does not exits"
          });
        }
      }
    });
}

Example

I hope you have Got node.js – What does body-parser do with express in nodejs And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

Related posts:

  1. NodeJS RESTful CRUD API and MYSQL – node js Restify Tutorial
  2. Nodejs Login and Registration with PHP MySQL and SQLite Example
  3. Create a RESTful API Authentication Using Laravel Passport – Grant Type Password
  4. Multiple image slider in html source code
AngularJSangularjs login authentication exampleangularjs node js authenticationangularjs php mysql login exampleangularjs with php backend examplecreating registration and login form in node.js and mongodbcreating registration and login form in node.js and mysqlsimple session with angularjs and phpuser authentication using angularjs php mysql

Post navigation

Previous Post:Full Forms Computer and Internet parts Related Important Full Form
Next Post:JavaScript Client side Password hashing and encryption

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 (2345) Python (99) Software (178) Software (90) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (147) Technology (2416) Tips and Tricks (130) Tools (214) Top10 (507) Trading (95) Trending (77) VueJs (250) Web Technology (113) webtools (200) wordpress (166) World (343)

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