How can I read this log.log file?
It currently console.log's:
{"type":"Buffer","data":[65,116,116,101,109,112,116,101,100,32,116,111,32,100,105,118,105,100,101,32,98,121,32,122,101,114,111,46,10]}
const displayLogFile = () => {
fs.readFile("./log.log", (err, file) => { //adding "utf-8" only logs a small portion of the .log file, but I was told this might be an async issue.
console.log(file);
});
};
log.log (local file):
Attempted to divide by zero.
Error: ENOENT: no such file or directory, open './NoFileNamedThis.txt'
at Object.openSync (fs.js:498:3)
at Object.readFileSync (fs.js:394:35)
at fileDoesNotExist (C:\Users.js:33:6)
at Object.<anonymous> (C:\Users:54:3)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: './NoFileNamedThis.txt'
}
Index was outside the bounds of the array.
TypeError: Cannot read property '0' of null
at arrayIsNull (C:\Users:44:6)
at Object.<anonymous> (C:\Users:66:3)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47
I would like to console.log() this .log, log file, but it console.log()'s an array buffer.
You're not specifying an encoding, so the file gets read as a Buffer.
If no encoding is specified, then the raw buffer is returned.
If options is a string, then it specifies the encoding:
readFile('/etc/passwd', 'utf8', callback);
const displayLogFile = () => {
fs.readFile("./log.log", "utf8", (err, file) => {
console.log(file);
});
};
to have it decoded into a string (assuming it's encoded in UTF-8).
Related
I am getting this error which I do not understand and am not able to fix.
The code is,
const fs = require('fs')
const Web3 = require('web3')
const { NonceTxMiddleware, SignedTxMiddleware, LocalAddress, CryptoUtils, HDWalletProvider } = require('#truffle/hdwallet-provider')
const client = new Client (
goerliChainId,
"https://eth-goerli.g.alchemy.com/v2/zEsvEP-zdgrdgdffgfgf64kuugnfvd6P",
"https://eth-goerli.g.alchemy.com/v2/oqB3MrwE1sdfgsdfgsdfgy5WD71Qj24n"
)
The error message is,
const client = new Client (
^
ReferenceError: Client is not defined
at Object.loadAccount (C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\utils\common.js:13:20)
at init (C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\Oracle.js:128:53)
at C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\Oracle.js:138:60
at Object.<anonymous> (C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\Oracle.js:149:3)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
I am not able to understand anything, please help.
const {web3js, myAccount} = require ('./utils')
const {bytecode} = require ('./contractartifact')
async function deploy() {
web3js.eth.sendTransaction({
from: myAccount.address,
data: bytecode,
gas: 800
})
.on('receipt', console.log)
}
deploy()
Error
C:\Users\giris\getter-setter\deploy.js:9
web3js.eth.sendTransaction({
^
TypeError: Cannot read properties of undefined (reading 'eth')
at deploy (C:\Users\giris\getter-setter\deploy.js:9:12)
at Object. (C:\Users\giris\getter-setter\deploy.js:19:1)
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
Your import is incorrect here:
const {web3js, myAccount} = require ('./utils')
It should be:
const web3js = new Web3(Web3.givenProvider || "ws://localhost:8545");
MyCode;
eventHandler.js
const reqEvent = async(event) => require(`../events/${event}`);
module.exports = async(client) => {
client.on("ready", () => reqEvent("ready")(client, "message"));
client.on("message", () => reqEvent("message"));
}
y client definition
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Discord.Intents.FLAGS.GUILD_VOICE_STATES
]
});
Error;
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an instance of Promise
at checkListener (node:events:128:3)
at _addListener (node:events:423:3)
at Client.addListener (node:events:487:10)
at module.exports (/app/util/eventHandler.js:5:12)
at Object.<anonymous> (/app/index.js:15:34)
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) {
code: 'ERR_INVALID_ARG_TYPE'
}
I can't solve this error, can anyone help with the solution?
I Used Google Translate. I'm Sorry If I Have Any Mistakes.
try this
module.exports = async(client) => {
client.on("message", (message)=> {
reqEvent(message.content);
});
};
I'm trying to compile solidity using node compile.js. I have attached the code below:
Here is my simple demo structure:
contracts
node_modules
compile.js
Incrementer.sol
package.json
package-lock.json
Here is compile.js
const fs = require('fs');
const solc = require('solc');
const path = require('path');
// Get Path and Load Contract
const inboxPath = path.resolve(__dirname, 'Incrementer.sol');
console.log(inboxPath) // This one provide directory to read (/Users/amstriker/Desktop/Sdax/OnePlace/contracts/Incrementer.sol'
const source = fs.readFileSync(inboxPath, 'utf8'); // still getting stuck on this
// Compile Contract
const input = {
language: 'Solidity',
sources: {
'Incrementer.sol': {
content: source,
},
},
settings: {
outputSelection: {
'*': {
'*': ['*'],
},
},
},
};
const tempFile = JSON.parse(solc.compile(JSON.stringify(input)));
const contractFile = tempFile.contracts['Incrementer.sol']['Incrementer'];
// Export Contract Data
module.exports = contractFile;
Incrementer.sol:
pragma solidity ^0.8.0;
contract Incrementer {
uint256 public number;
constructor(uint256 _initialNumber) {
number = _initialNumber;
}
function increment(uint256 _value) public {
number = number + _value;
}
function reset() public {
number = 0;
}
}
Packages.json
{
"dependencies": {
"solc": "^0.8.0",
"web3": "^1.5.3"
}
}
I have been tried many different approach but still getting errors:
internal/fs/utils.js:314
throw err;
^
Error: ENOENT: no such file or directory, open
'/Users/amstriker/Desktop/Sdax/OnePlace/contracts/Incrementer.sol'
at Object.openSync (fs.js:498:3)
at Object.readFileSync (fs.js:394:35)
at Object.<anonymous> (/Users/amstriker/Desktop/Sdax/OnePlace/contracts/compile.js:7:19)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/Users/steven/Desktop/Sdax/OnePlace/contracts/get.js:2:17)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)
at internal/main/run_main_module.js:17:47 {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: '/Users/amstriker/Desktop/Sdax/OnePlace/contracts/Incrementer.sol'
}
Any helps would be appreciated!!.
It failed because of space solidity filename( Incrementer.sol). It is working fine after i changed from Incrementer.sol to Incrementer.sol.
I have an issue that I can't seem to resolve, mostly because I have little knowledge of why it is occurring in this particular scenario.
Here's the error :
TypeError: Cannot read property 'followers' of undefined
at Object.<anonymous> (C:\Users\username\Documents\My Lib\bot\src\bot.js:15:4)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:393:7)
at startup (bootstrap_node.js:150:9)
at bootstrap_node.js:508:3
and here's what the code looks like :
const Twit = require('twit'),
config = require('./config'),
init = new Twit(config);
function Twitter(twitter) {
this.twitter = twitter
}
Twitter.prototype.followers = function(params) {
this.twitter.get('followers/list', params, (err, data) => {
if (!err)
data.users.forEach(user => console.log(data))
})
};
var bot = Twitter(init);
bot.followers({ screen_name: 'myscreenname'})
Haha. I'm almost certain it's a silly mistake. I just can't seem to find the source.
Any help is and will be appreciated.
You forgot the new keyword. Try this:
var bot = new Twitter(init);