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

JSP to JSP Communication: A Complete Guide to Dynamic Java Web Development

Java Server Pages (JSP) is a powerful technology used to develop dynamic web applications by…

5 days ago

Which Frontend Framework to Use with Spring Boot?

Spring Boot is a powerful backend framework for developing Java-based web applications. Pairing it with…

6 days ago

Is Java Spring Boot Still Relevant in 2025?

The Rise of Spring Boot As technology advances, frameworks and tools that developers depend on…

6 days ago

How to Check Laravel Print Version: A Simple Guide

Laravel Print Version: An Essential Guide Laravel is a powerful PHP framework widely used for…

6 days ago

How to Laravel cache clear

Laravel cache clear , you can use the Artisan command-line tool that comes with Laravel.…

7 days ago

Installing Vue.js in Laravel Project

Vue.js is a powerful JavaScript framework for creating dynamic user interfaces, while Laravel is a…

7 days ago