Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
query the content from mysql in js

I want to retrieve content from MySQL to a web page. I tried to use node.js, I created a server on it, but I can't find how to link it to a webpage. How to pass parameter in node?

I need to load content from a table depending on the parameter in the link. (title, description, etc.) Example: localhost:63342/MySite/project.html?projectname=mygame

Parameter extraction code in webpage:

<script>
            var params = window
                    .location
                    .search
                    .replace('?','')
                    .split('&')
                    .reduce(
                            function(p,e){
                                var a = e.split('=');
                                p[ decodeURIComponent(a[0])] = decodeURIComponent(a[1]);
                                return p;
                            },
                            {}
                    );
        </script>

Node.js server code:

const http = require("http");
http.createServer(function(request,response){

    response.end("Hello NodeJS!");

}).listen(3000, "127.0.0.1",function(){
    console.log("Сервер начал прослушивание запросов на порту 3000");
});

const mysql = require("mysql2");

const connection = mysql.createConnection({
    host: "localhost",
    user: "username",
    database: "databasename",
    password: "pass"
});

connection.connect(function(err){
    if (err) {
        return console.error("Ошибка: " + err.message);
    }
    else{
        console.log("Подключение к серверу MySQL успешно установлено");
    }
});

connection.query("SELECT * FROM ProjectsData",
    function(err, results, fields) {
        console.log(err);
        console.log(results); // собственно данные
        //console.log(fields); // мета-данные полей
    });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I moved the whole site to a Node.js host, using Handlebars for page rendering and express.router for easy parameter management.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!