Fetch data from mongoDb and display it in html without using ejs
NickName:Soham Ask DateTime:2022-11-24T19:13:47

Fetch data from mongoDb and display it in html without using ejs

Basically I'm new to nodeJS, I wanted to display the mongoDb data in html table without using ejs as I have created other pages using html. I have found similar questions but they have given solution for the ejs file.

This is my app.js code

var express = require("express");
var bodyParser = require("body-parser");
const mongoose = require('mongoose');

mongoose.connect('mongodb://localhost:27017/RailwayTicket');
var db = mongoose.connection;
db.on('error', console.log.bind(console, "connection error"));
db.once('open', function (callback) {
    console.log("connection succeeded");
})

var app = express()


app.use(bodyParser.json());
const path = require("path")
const static_path = path.join(__dirname, "../../frontend/");
app.use(express.static(static_path));
app.use(bodyParser.urlencoded({
    extended: true
}));

app.post('/sign_up', function (req, res) {
    var name = req.body.name;
    var email = req.body.email;
    var phone = req.body.phone;
    var pass = req.body.password;

    var data = {
        "name": name,
        "email": email,
        "phone": phone,
        "password": pass
    }
    db.collection('sign_up').insertOne(data, function (err, collection) {
        if (err) throw err;
        console.log("Record inserted Successfully");

    });

    return res.redirect('loggedIn.html');
})


app.get('/', function (req, res) {
    res.set({
        'Access-control-Allow-Origin': '*'
    });
    return res.redirect('index.html');
}).listen(3000)


console.log("server listening at port 3000");

Copyright Notice:Content Author:「Soham」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/74559850/fetch-data-from-mongodb-and-display-it-in-html-without-using-ejs

More about “Fetch data from mongoDb and display it in html without using ejs” related questions

Fetch data from mongoDb and display it in html without using ejs

Basically I'm new to nodeJS, I wanted to display the mongoDb data in html table without using ejs as I have created other pages using html. I have found similar questions but they have given soluti...

Show Detail

Can we send data from mongoDB to HTML?

I am working on a Mini Project where I have stored data coming from a form in my DataBase(MongoDB). Now I want to fetch data from MongoDB and want to add it to HTML(as a list) to display on the web...

Show Detail

how to fetch data from mongodb and display it in a table using node js?

I'm having trouble figuring out how can I retrieve data in mongodb and fetch it in an html/ejs file. in html/ejs file there is one button where if the user click it, it will display all data in dat...

Show Detail

Display MongoDB Collection Data in HTML

So I'm new to MongoDB. I am developing a website that I would like to GET data from a MongoDB collection based on a {Name: String} within that Collection and display it in an HTML Table. This is...

Show Detail

How to get data from mongodb and display in ejs page

I am using mongodb and mongoose for my database. How can I retrieve data from mongodb using nodejs and display the contents in an ejs page? I have searched a lot and I still couldn't find the solut...

Show Detail

How to retrieve data from mongodb and display in ejs page?

I have already added data to mongodb. I am using mongoose. I want to get data from mongodb database and display that in ejs page. I have searched a lot in the internet but I am getting errors while

Show Detail

Mongodb display searched document data in ejs file

I am trying to make it so that if I search for a name that Mongodb would search for that document and then that it would display it in the ejs file. And it should do that by changing the text field...

Show Detail

How to fetch data from Mongodb and display it in respective html form fields?

I have successfully fetched and saved the data from a html form named inserted_data.html and saved in my mongobd, now i want to display that data in the form fields of another html file named user_...

Show Detail

using fetch api function to get data from MongoDB and display them in node.js

I have a node application which inserts different types of courses into mongodb and displays them onto the web page directly from the database. i want to use the fetch() api function to get the dat...

Show Detail

can't fetch data from mongodb and display that into html

model named Field.js const mongoose = require('mongoose'); mongoose.connect('mongodb://localhost:27017/SuperchainV1', { useNewUrlParser: true }); mongoose.set('useNewUrlParser', t...

Show Detail