in Education by
here is my code. var http=require("http"); var fs = require("fs"); var express = require("express"); var app = express(); var path = require("path"); var mysql = require('mysql'); var ejs = require("ejs") var bodyParser = require('body-parser'); app.set('view engine' , 'ejs'); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); var con = mysql.createConnection({ host: "localhost", user: "root", password: "", database: "testn" }); con.connect(function(err) { if (err) throw err; con.query("SELECT * FROM form", function (err, result, fields) { if (err) throw err; console.log(JSON.stringify(result)); app.get('/', function(req, res) { res.render('index',{data:JSON.stringify(result)}); }); }); }); app.listen(3010); console.log("Running at Port 3010"); Run code snippetExpand snippet and here is my html <!DOCTYPE html> Document

<%=data%>

Run code snippetExpand snippet and here is my output [{"name":"Prakash","email":"[email protected]","description":"uykiukjk"},{"name":"Mathan","email":"[email protected]","description":"uykiukjk"},{"name":"prakashvpsm","email":"[email protected]","description":"uykiukjk"},{"name":"Prakash","email":"[email protected]","description":"wddfwdpfk"},{"name":"Prakash","email":"[email protected]","description":"uykiukjk"}] but i dont want in json format .i want without only the data. The data is fetched from local server JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
I am guessing the solution below is what you were looking for. const express = require("express"); const app = express(); const mysql = require('mysql'); const bodyParser = require('body-parser'); app.set('view engine', 'ejs'); app.use(bodyParser.urlencoded({ extended: false })); app.use(bodyParser.json()); const con = mysql.createConnection({ host: "localhost", user: "root", password: "", database: "testn" }); con.connect(function (err) { if (err) throw err; }); app.get('/', function (req, res) { const result = con.query("SELECT * FROM form", function (err, result, fields) { if (err) throw err; return results; }); res.render('index', { data: results }); }); app.listen(3010); console.log("Running at Port 3010"); ejs template <!DOCTYPE html>
<% for(const row of data) { %> <% } %>
<%= row.name %> <%= row.email %> <%= row.description %>

Related questions

0 votes
    I am trying to create a simple node.js app on heroku. Here is app.js: console.log("Starting App" ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I want to build my js/css code, write it on disk and serve it using webpack-dev-server in a ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I have a problem, I want to move value of Object[0] nazwa, which is a result of query (let's ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I have a problem, I want to move value of Object[0] nazwa, which is a result of query (let's ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 23, 2022 in Education by JackTerrance
0 votes
    Is it possible to add a property (with get and set method) to the scope of a file without making ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 19, 2022 in Education by JackTerrance
0 votes
    I have been implementing a Next.js app for a side project of mine. It is a basic brochure-style ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    I copied and pasted a for-await-of example from MDN and still get an error telling me await is a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I copied and pasted a for-await-of example from MDN and still get an error telling me await is a ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    How to display JSON in an easy-to-read (for human readers) format?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    When I run a new page, I must specify size of the viewport using the setViewport function: await page ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I want to reuse a code snippet which will save me A WHOLE LOT OF TIME. I want to make POST, ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I am using the electron-quick-start app with a windows machine. I have added logging statements in the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 26, 2022 in Education by JackTerrance
0 votes
    I am using the electron-quick-start app with a windows machine. I have added logging statements in the ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 20, 2022 in Education by JackTerrance
0 votes
    I am using react FineUploaderS3, with params: this.myUploader = new FineUploaderS3({ options: { request: { ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I have a particular context in which one data are transformed a lot to get transferred across network. At ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 26, 2022 in Education by JackTerrance
...