[Solved] What is happening here in this code? [closed]

The util module has exported an object that contains (probably amongst others) a function under the key inherits: exports = { inherits: function() … } The express module on the other hand, has directly exported a whole function, and that function is immediately invoked and the result assigned to the variable express. module.exports = exports … Read more

[Solved] How do I reduce this code to one line?

See Frits’ answer: You can, but is there really any need? It’s nice and readable the way you’ve done it. But if you really, really want to, this is how: exports.about = function(req, res){ res.render(‘about’, {title: ‘about page’, time: new Date().toLocaleDateString() }); }; It looks a bit odd, but the new Date() part takes precedence, … Read more

[Solved] Can some one provide a link to create a simple http server and client using node js [closed]

I found these resources helpful: “The Node Beginner Book”, Building your first node.js app (series), “NowJS and Node.js Tutorial – Creating a multi room chat client”, “Beginner’s Guide To Node.Js”, and “Node.js & WebSocket – Simple chat tutorial”. These should get you up to speed with using Node.JS Good luck! solved Can some one provide … Read more

[Solved] What is the best way to query data conditionally in MongoDB (node.js)?

To come up with a functioning MongoDB query that determines whether a user is part of a group requires an understanding of how you’re structuring your database and groups collection. One way to structure that is like so: { “_id” : ObjectId(“594ea5bc4be3b65eeb8705d8”), “group_name”: “…”, “group_members”: [ { “user_id”: ObjectId(“<same one from users collection”), “user_name”: “Alice”, … Read more

[Solved] Nodejs assync function return

I think this code solve your issue , you have to wait until each request is completed function pegaCaminho(id) { return new Promise((resolve,reject)=>{ api.get(`/tratadadoscatdigito/caminho/${id}`) .then(function (response) { // handle success //console.log(response.data); resolve(response.data) }) .catch(function (error) { console.log(error); reject(error) }); }) } const trataDadosCatDigitoComCaminho = async (req, res) => { const string = dados; const separaLinha … Read more

[Solved] remove JSON array in node js

Considering that you are working with strings: var s = JSON.stringify([{“id”:1, “name”:”firstname”}, {“id”:2, “name”:”secondname”}]) var result = s.substring(1, s.length – 1) Given that I’m not sure you really need something like that. solved remove JSON array in node js

[Solved] SyntaxError: Unexpected token ‘const’ [closed]

You are saying if(!Events.includes(event.name)) const L = file.split(“/”); Which doesn’t make sense because const is block scoped. You forgot {} if (event.name) { if(!Events.includes(event.name)) { const L = file.split(“/”); return Table.addRow(`${event.name || “MISSING”}`, `⛔ Event name is either invalid or missing ${L[6] + `/` + L[7]}`); } } solved SyntaxError: Unexpected token ‘const’ [closed]

[Solved] nodejs – array search and append

Your objects initial value: var myObj = [{‘ABC’: ‘5’}, {‘BCD’: ‘1’}] Now if DDD doesn’t exists, just add it: var DDD = “3” var DDDExists = false; myObj.forEach(function(){ if(this.DDD.length > 0){ // If it exists, break the loop DDDExists = true; break; } }) // If DDD doesn’t exists, add it if(DDDExists === false){ // … Read more

[Solved] How to make a Discord bot delete its own message from a DM? (Discord.js)

Here, ‘recipient’ is the person you are sending a message to: recipient.send(“This is sent to your dm!”).then(m => { m.delete(10000) //Deletes the message after 10000 milliseconds (10 seconds) } Next time, try and do a little research first. You can also read the docs for discord.js which likely do have this issue. solved How to … Read more

[Solved] How to add “reason” thing to ban command

Simply use member.ban(‘reason here’). Use an object if you need to delete previous messages and supply a reason, like so: member.ban({days: 2, reason: ‘bad’}); Now, just use this setup with the user’s reason. Use a variable for the reason as a sliced version of the arguments array, joined with spaces. Edit: Showing context… if (message.content.toLowerCase().startsWith(‘+ban’)) … Read more

[Solved] NodeJs function wait until callback return value

make your function async and then await xyz() var http = require(‘http’); var foo = async function(req, res){ var a = await xyz(‘5’); res.end(a); console.log(a); } function xyz(arg){ var aa = 55; return aa; } http.createServer(foo).listen(8000); console.log(‘start server’); 2 solved NodeJs function wait until callback return value