Node JS

Registration Form using Node js Angular Mongodb

In this Article explains how to create registration using Node js and Mongodb and Angular .Node js as backend front end angular.

First you have to Create the Project

index.js

const express = require('express');
const app = express();
const mongoose = require('mongoose');
mongoose.set('strictQuery', true);
var routes = require('./routes/routes');
const cors = require('cors');

app.use(cors(
    {
      origin: "http://localhost:4200"
    }
   
  ));

mongoose.connect("mongodb://127.0.0.1:27017/dbschool",{useNewUrlParser: true,  useUnifiedTopology: true },
function checkDB(error)
{
    if(error)
    {
        console.log(error)
    }
    else
    {
        console.log("DB Connectedddd!!!!!!!!!!!")
    }
});


app.listen(8086,function port(error)
{
    if(error)
    {
        console.log(error)
    }
    else
    {
        console.log("Port  Connectedddd!!!!!!!!!!! 8086")
    }
});

app.use(express.json());
app.use(routes);

employeeController.js

var employeeModel = require('./employeeModel');

var createUserControllerFn = async (req, res) => 
{
    try
{
    const body = req.body
    const employeeModelData = new employeeModel()
    employeeModelData.name = body.name
    employeeModelData.address = body.address
    employeeModelData.phone = body.phone
    await employeeModelData.save()

    res.status(200).send({
        "status": true, "message": "Employee created successfully" 
    });
}
catch(error)
{
    res.status(400).send(error);
}

}
module.exports = { createUserControllerFn };

employeeModel.js

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var employeeSchema = new Schema({

    name: {
        type: String,
        required: true
    },
    address: {
        type: String,
        required: true
    },
    phone: {
        type: String,
        required: true
    }
  
});

module.exports = mongoose.model('employee', employeeSchema);

routes.js

const express = require('express');

const router = express.Router();
var employeeController = require('../src/employee/employeeController');

// router.post('/user/create', function(req, res) { employeeController.createUserControllerFn });
router.route('/user/create').post(employeeController.createUserControllerFn);

router.route('/user/findOne').get(employeeController.findOneUserController);
module.exports = router;

Installing Angular CLI

admin

Recent Posts

Employee Working Hours Calculation System using C#.net

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

1 week ago

Java Payroll System Calculate Employee Overtime

Act as a Java developer to create a program that calculates the gross wage for…

2 weeks ago

Employee Working Hours Calculation System using Java

Initialize the employee number, Hourswork,and Hoursrate to calculate a grosswage use the following condition. if…

2 weeks ago

Laravel 11 School Management System

In this tutorial, we will teach you how to create a simple school management system…

2 weeks ago

How to Make Admin Panel Using React MUI

I have design the Admin Basic templete using React MUI Design Admin Dashboard and Login.Here…

4 weeks ago

Install Laravel Breeze for Authentication Using Laravel 11

In this tutorial ,i am to going teach the Laravel Breeze.Laravel Breeze provides a simple…

1 month ago