177
178 try {
179 response.send(str)
180 } catch(err) {181 console.error(err)
182 }
183 })
49 process.stderr.write(tolog); //just write it to stderr
50 }
51 else {
52 appendFile(__dirname + "/logs/" + time, tolog, function (err) { 53 if (err) {
54 process.stderr.write(err);
55 }
425 threshold: 1024 * 16
426 }
427});
428wss.on("connection", function connection(ws) {429 ws.channel = "everyone";
430 console.log(5,"new connection");
431 ws.on("message", function incoming(message) {
41 }).toBuffer().then(function(data){
42 writeFileSync(avatars + filename,data)
43 let sql = `update ipost.users set User_Avatar=? where User_Name=?`;
44 con.query(sql, [filename, encodeURIComponent(res.locals.username)], function (err) { 45 if (err)
46 throw err;
47 res.json({ "success": "updated avatar" });
146 throw err;
147 if (result[0]) {
148 let sql = `update ipost.users set User_PW=? where User_Name=? and User_PW=?;`;
149 let values = [hashed_new_pw, res.locals.username, hashed_pw];150 con.query(sql, values, (err2) => {
151 if (err2)
152 throw err2;
Two variables can have the same name if they're declared in different scopes.
In the example below, the parameter x
is said to "shadow" the variable x
declared above it.
The outer x
can no longer be accessed inside the sum
function.
const x = 1
function add(x, y) {
return x + y
}
While shadowing does not cause any problems most of the time, it does make the code harder to read and understand. We highly recommend against shadowing. However, if you want to shadow some variable name and don't want DeepSource to flag it, add a skipcq comment alongside an explanation:
const x = 1
function add(x, y) { // skipcq: JS-0123 - `x` can be safely shadowed
return x + y
}
If you want to disable this issue project-wide, you can add it to the list of disabled issues in the project dashboard.
const file = "data.txt"
function readFile(file) {
// The parameter `file` shadows the toplevel variable `file`.
if (fs.existsSync(file)) {
return fs.readFileSync(file)
}
return null
}
// Prefer variable names that are distinct and convey as much
// meaning as possible.
const dataFile = "data.txt"
function readFile(filePath) {
if (fs.existsSync(filePath)) {
return fs.readFileSync(filePath)
}
return null
}
Alternatively:
const file = "data.txt"
function readFile(file) { // skipcq: JS-0123 - Shadowing is safe here
// ...
}