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

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

3 weeks ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

1 month ago

Build Your First Responsive Login Form Using HTML and CSS FlexBox

Creating a responsive login form is a crucial skill for any web developer. In this…

1 month ago

Build Crud API with Laravel 12

In this tutorial will teach  Laravel 12 CRUD API  by step. Laravel  10 CRUD Application …

2 months ago

laravel 12 image upload tutorial

In this lesson we talk about laravel 12 image uploading and display the image step…

2 months ago

Laravel 12 CRUD Application

In this tutorial will teach Laravel 12 CRUD Application step by step. Laravel  12 CRUD…

2 months ago