Open Dadda97 opened 4 years ago
JSHint returned a point that did not exist in the document being edited. Rule: W033 Requested point: 21:47
W033
var http = require('http'); var mysql = require('mysql') var url = require('url') const headers = { "Content-Type": "application/json" } const db_connection = mysql.createPool({ connectionLimit: 10, host: 'db', user: 'node', password: 'password', database: 'node' }); // db_connection.connect(); //create a server object: const server = http.createServer((req, res) => { res.setHeader('Access-Control-Allow-Origin', '*'); let api = url.parse(req.url, true).pathname switch (req.method) { case 'GET': try { // res.write(db_connection.query("SELECT * FROM USER_PRIVILEGES")) let result = []; db_connection.getConnection(function(err, conn) { if (err) res.write("Error") else { let query if (!api.includes("floor")) query = "SELECT * FROM DATA" else { let floor = api.split('/')[2] console.log(floor) query = "SELECT * FROM DATA WHERE (Location = \"" + floor + "\")" } conn.query(query, function(err, rows) { if (err) res.write("Error in query") else { rows.forEach(element => { str = `{"id": "${element.id}","Time": "${element.Time}","Location": "${element.Location}"}` result.push(JSON.parse(str)) }); result = JSON.stringify(result) res.writeHead(200) res.write(result) res.end() } }) } }) } catch (error) { console.log(error) } break case 'POST': let received = "" req.on('data', chunk => { console.log(`Received ${chunk.length} bytes of data`) received += chunk }) req.on('end', () => { console.log("No more data") let obj = JSON.parse(received) console.log(obj.id) db_connection.getConnection(function(err, conn) { if (err) res.write("Cannot get DB connection") else { conn.query(`INSERT INTO DATA values ('${obj['id']}', '${obj['Time']}', '${obj['Location']}')`, function(err, rows) { if (err) res.write("Error in insert") else { res.writeHead(200, headers) res.write(`1 record inserted`) res.end() } }) } }) }) break default: res.writeHead(405, headers) res.end(`${JSON.stringify({error: 'Method not allowed', method: req.method})}\n`) } }).listen(3000); //the server object listens on port 8080
Debug information:
Atom version: 1.49.0 linter-jshint version: v3.1.19 JSHint version: jshint v2.11.0 Hours since last Atom restart: 0 Platform: linux Current file's scopes: [ "unknown" ] linter-jshint configuration: { "executablePath": "", "lintInlineJavaScript": false, "disableWhenNoJshintrcFileInPath": false, "scopes": [ "source.js", "source.js-semantic" ], "jshintFileName": ".jshintrc", "jshintignoreFilename": ".jshintignore" }
JSHint returned a point that did not exist in the document being edited. Rule:
W033
Requested point: 21:47Debug information: