Im am new to node.js and get the mentioned error in server.js file.

I am trying to introduce a gantt diagramm with dhtmlx library.

I am using Node v16.13.1 and IntelliJ 2021.3

Below are my code snippets.

Index.xhtml:

<!DOCTYPE html>
    <head>
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">
        <title>QuickInfo extension</title>
        <script src="https://cdn.dhtmlx.com/gantt/edge/dhtmlxgantt.js"></script>

        <link href="https://cdn.dhtmlx.com/gantt/edge/dhtmlxgantt.css" rel="stylesheet">

        <style type="text/css">
            html, body{
                height:100%;
                padding:0px;
                margin:0px;
                overflow: hidden;
            }

        </style>
    </head>

    <body>
    <div id="gantt_here" style='width:100%; height:100%;'></div>
    <script>
        gantt.config.date_format = "%Y-%m-%d %H:%i:%s";
        gantt.init("gantt_here");
    </script>
    </body>

Server.js:

 var express = require('express');
        var bodyParser = require('body-parser');
        var path = require('path');

        var port = 1337;
        var app = express();

        app.use(express.static(path.join(__dirname, "public")));
        app.use(bodyParser.urlencoded({ extended: true }));

        app.listen(port, function(){
            console.log("Server is running on port "+port+"...");
        });

        var Promise = require('bluebird');
        require("date-format-lite");

        var mysql = require('promise-mysql');
        var db = mysql.createPool({
            host: 'localhost',
            user: 'root',
            password: '',
            database: 'gantttutorial'
        });

        app.get("/data", function (req, res) {
            Promise.all([
                db.query("SELECT * FROM gantt_tasks"),
                db.query("SELECT * FROM gantt_links")
            ]).then(function(results){
                var tasks = results[0],
                    links = results[1];

                for (var i = 0; i < tasks.length; i++) {
                    tasks[i].start_date = tasks[i].start_date.format("YYYY-MM-DD hh:mm:ss");
                    tasks[i].open = true;
                }

                res.send({
                    data: tasks,
                    collections: { links: links }
                });

            }).catch(function(error) {
                sendResponse(res, "error", null, error);
            });
        });

nodeJsProblem.PNG

Has anyone an idea what I am doing wrong?

Please verify your location/url which is /data I think you need to put the full path url there like http://localhost/x/data

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.