So I'm trying to code with node.js for the first time, and have very small prior coding knowledge. I'm trying to code a steam trading bot, but I'm already stumped at the basics of it. This is the code I have, titled "bot.js":
const SteamUser = require('steam-user');
const client = new SteamUser();
const config = require('./config.json');
const logOnOptions = {
accountName: config.username,
password: config.password
};
client.logOn(logOnOptions);
client.on('loggedOn', () => {
console.log('Succesfully logged on.');
});
In the config.json file I just have the username and password which are fine. My problem is that when typing in node bot.js after installing steam-user, I get this error:
module.js:471
throw err;
^
Error: Cannot find module 'C:\Users\Name\Desktop\bot\bot.js'
at Function.Module._resolveFilename (module.js:469:15)
at Function.Module._load (module.js:417:25)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
Help?
This is not an error with your code, but an error node is throwing saying it can't find bot.js in your directory C:\Users\Name\Desktop\bot
Verify that that is the directory where bot.js lives and that the file name is indeed bot.js. Also make sure there are no hidden extensions, the file could possibly be bot.js.txt.
Related
This question already has answers here:
How do I fix CLIENT_MISSING_INTENTS error?
(5 answers)
Discord.js v12 code breaks when upgrading to v13
(1 answer)
Closed 1 year ago.
I've tried to create a bot on discord, and with multiple tutorials, I've followed all of the instructions, and it seems to work fine in the beginning. However, with all of the tutorials, I'm met with one problem. In my index.js file for my bot, when I open the VSCode terminal and type in the command node index.js (which is supposed to make my bot go online, I get the following error messages:
/Users/myname/Desktop/testbot/node_modules/discord.js/src/client/Client.js:544
throw new TypeError('CLIENT_MISSING_INTENTS');
^
TypeError [CLIENT_MISSING_INTENTS]: Valid intents must be provided for the Client.
at Client._validateOptions (/Users/myname/Desktop/testbot/node_modules/discord.js/src/client/Client.js:544:13)
at new Client (/Users/myname/Desktop/testbot/node_modules/discord.js/src/client/Client.js:73:10)
at Object.<anonymous> (/Users/myname/Desktop/testbot/index.js:2:13)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47 {
[Symbol(code)]: 'CLIENT_MISSING_INTENTS'
}
I have node.js 16.13.0, and discord.js installed. My bot is a member of my server, but it's always offline. What can I do to fix it?
Here's the code for index.js:
const Discord = require('discord.js');
const bot = new Discord.Client();
const token = '[not putting my token online]';
const PREFIX = '';
bot.on('ready', () => {
console.log('Online!');
});
bot.login(token);
It seems like you don't have intents added with your bot which is needed to get it running according to the discord.js starter guide
// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const token = 'your token here';
// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// When the client is ready, run this code (only once)
client.once('ready', () => {
console.log('Ready!');
});
// Login to Discord with your client's token
client.login(token);
I copied a code from StackOverflow to read text from a base64 of an image:
let base64 = req.body.toString("base64");
let imageBuffer = Buffer.from(base64, "base64");
const worker = createWorker();
(async () => {
await worker.load();
await worker.loadLanguage('eng');
await worker.initialize('eng');
console.log("Recognizing...");
const { data: { text } } = await worker.recognize(imageBuffer);
console.log("Recognized text:", text);
await worker.terminate();
})();
But I a getting this Error:
Error opening data file ./eng.traineddata
Please make sure the TESSDATA_PREFIX environment variable is set to your "tessdata" directory.
Failed loading language 'eng'
Tesseract couldn't load any languages!
Recognizing...
AdaptedTemplates != nullptr:Error:Assert failed:in file /workspace/tesseract/src/classify/adaptmatch.cpp, line 196
undefined
undefined
C:\Users\jaysm\OneDrive\Desktop\QBase\node_modules\tesseract.js\src\createWorker.js:173
throw Error(data);
^
Error: RuntimeError: abort(undefined). Build with -s ASSERTIONS=1 for more info.
at ChildProcess.<anonymous> (C:\Users\jaysm\OneDrive\Desktop\QBase\node_modules\tesseract.js\src\createWorker.js:173:15)
at ChildProcess.emit (events.js:315:20)
at emit (internal/child_process.js:903:12)
at processTicksAndRejections (internal/process/task_queues.js:81:21)
[nodemon] app crashed - waiting for file changes before starting...
What is the problem with my code?
I found some solutions of this error but they were with python or some other languages but none with NodeJS.
Actually my problem was not of setting TESSDATA_PREFIX as environment variable but i had not placed the eng.traineddata file in the base directory.
I placed the eng.traineddata file and the issue was resolved!
I'm following this video tutorial on the MERN stack and I'm unable to connect to MongoDB for some very strange reason. This issue has been frustrating me quite a bit since I'm probably just missing something very basic, so please forgive me if the answer is painfully obvious to you.
The video uses mlab for MongoDB, which is no longer available, so I'm instead using MongoDB Atlas. The key I'm supposed to use to connect my application to the database is this:
mongodb+srv://<username>:<password>#fs-shopping-list.6rzkd.mongodb.net/<dbname>?retryWrites=true&w=majority
My password doesn't contain any special characters, and my IP address is on the whitelist. As for dbname, I have one database named "data" with a collection called "items," so I'm using "data" for dbname.
The code in question that is causing my problem is in a file called server.js:
const db = require('./config/keys').mongoURI; // I keep my key in a separate file in the way shown in the video
// Connect to MongoDB
mongoose
.connect(db, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log('MongoDB connected.'))
.catch(err => console.log(err));
I keep getting this error when I try to run the server (I edited out my name from some of the paths):
{ MongooseServerSelectionError: bad auth Authentication failed.
at NativeConnection.Connection.openUri (/fs_shopping_list/node_modules/mongoose/lib/connection.js:828:32)
at Mongoose.connect (/fs_shopping_list/node_modules/mongoose/lib/index.js:335:15)
at Object.<anonymous> (/fs_shopping_list/server.js:15:6)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
message: 'bad auth Authentication failed.',
reason:
TopologyDescription {
type: 'ReplicaSetNoPrimary',
setName: null,
maxSetVersion: null,
maxElectionId: null,
servers:
Map {
'fs-shopping-list-shard-00-01.6rzkd.mongodb.net:27017' => [ServerDescription],
'fs-shopping-list-shard-00-02.6rzkd.mongodb.net:27017' => [ServerDescription],
'fs-shopping-list-shard-00-00.6rzkd.mongodb.net:27017' => [ServerDescription] },
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null } }
Can someone please help me find out what I'm doing wrong so I can continue the tutorial? Thank you for your time.
EDIT: I don't think adding another account for database access will solve the problem, since admin accounts on MongoDB have the ability to read and write to their databases. The only thing I can think of that is possibly stopping me is maybe my Norton antivirus, although I'm not sure how to test this hypothesis.
Here an example of how I do it with mongoose:
const connectToMongo = async () => {
try {
await mongoose.connect(mongoUrl, { useNewUrlParser: true });
console.log('connected to MongoDB');
} catch(error) {
console.log('error connection to MongoDB:', error.message);
}
};
Here is an example of the mongoUrl: mongo+srv://username:password#cluster0-ipl5c.mongodb.net/collectionname?retryWrites=true
Please make sure that you create a user to read and write to the database that isn't the admin account. The URI string you get from the "Connect" button might use the admin account even though that's not the account you want to use in the URI string, so keep that in mind. If you did that and you're still unable to connect, please use this checklist:
check that correct IP is whitelisted
check that user has correct rights
check that you are using the right database name (collection)
check if you have special characters in your password (https://docs.atlas.mongodb.com/troubleshoot-connection/#special-pass-characters)
Try to add dbName in options:
await mongoose.connect('mongodb://root:example#mongo:27017', { dbName: "blog" });
i am currently trying to connect to a MySQL server on the internet using Node.Js with the mysql or the mysql2 NPM dependencies to use queries and other related stuff.
the code is simple...
//i import my dependency
const mysql = require('mysql2') //either 'mysql' or 'mysql2'
//i create my pool to create connections as needed
var conn = mysql.createPool({
host: 'some_database_i_have_access_to.mysql.uhserver.com',
user: 'valid_user',
password: 'valid_password',
database: 'some_existing_database'
})
//i try to connect (this is the part where it fails)
conn.getConnection((err,conn) => {
if (err) throw err //<- the error is thrown here
//i do query stuff
conn.query("SELECT * FROM atable",(err,res,firlds) => {
if(err) throw err
console.log(JSON.stringify(res))
})
//i close the connection
conn.end()
})
yet i always get an Error like this:
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
--------------------
at Protocol._enqueue (C:\Users\Aluno\Desktop\my-project\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\Aluno\Desktop\my-project\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Users\Aluno\Desktop\my-project\node_modules\mysql\lib\Connection.js:118:18)
at Object.<anonymous> (C:\Users\Aluno\Desktop\my-project\private\dtp-mysql.js:13:6)
at Module._compile (internal/modules/cjs/loader.js:707:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
at Module.load (internal/modules/cjs/loader.js:605:32)
at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
at Function.Module._load (internal/modules/cjs/loader.js:536:3)
at Module.require (internal/modules/cjs/loader.js:643:17)
all i know about the error is that the connection abruptly closes in one of the sides as stated in this question (Node js ECONNRESET), but nothing more, and creating singular connections does not solve this issue for me either.
any fixes to that?
you can also ref below url.
error while inserting LARGE volume data in mysql by using node.js (error code: 'ECONNRESET')
I have fixed this issue. It is caused by the default definition max_allowed_packet. Find max_allowed_packet in my.ini (C:\ProgramData\MySQL\MySQL Server 5.7). Update to 'max_allowed_packet=64M'. Restart mysql. Done.
Hi I know this was asked some time ago, but is it possibly because you're using:
conn.end()
Since you're using a Pooled connection, I think you can release the connection using
conn.release()
Or
conn.destroy()
Currently, you just log on to the ssh with putty.
We're trying to run a js file which then basically creates an empty log file, currently we're just getting this error:
port : '1157', ^^^^ SyntaxError: Unexpected identifier at exports.runInThisContext (vm.js:73:16) at Module._compile (module.js:443:25) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12) at Function.Module.runMain (module.js:501:10) at startup (node.js:129:16) at node.js:814:3
Here's the code we think is the problem:
var mysqlInfo;
mysqlInfo = {
host : https//www.random.com, port : '2332',
user : 'test#localhost', password : '32323232',
database : 'test_installation',
charset : 'utf8_general_ci'
};
we're not sure how to format it
Another problem is we get multiple connecting issues, but I think this is the main problem.
details edited out for security, but same format as our actual file
There are few things which i noticed,
first install mysql node module
then require it in you js
the code which you wrote is for exporting module. and as per your question it seems you want to connect to mysql db.
please use the code given below and run it using node connect.js command it will work for you.
var mysql = require("mysql");
var con = mysql.createConnection({
host : https//www.random.com,
port : '2332',
user : 'test#localhost',
password : '32323232',
database : 'test_installation',
charset : 'utf8_general_ci'
});
con.connect(function(err){
if(err){
console.log('Error connecting to Db');
return;
}
console.log('Connection established');
});
Thanks
Amit