I have a problem, when I debug on visual studio code, it gives me this error message "Uncaught Error: Cannot find module './command/$(files)'
Require stack:
"c:\Users\user\OneDrive\Bureau\himetsubabot\index.js"
however I put the right path and my file is called commande, here is the code
const fs = require('fs');
const Discord = require('discord.js');
const bot = new Discord.Client()
const config = require ("./config.js");
bot.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./commande').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require('./commande/$(files)')
client.command.set(command.name, command)
}
bot.on("ready", async message => {
console.log("Le bot démarre")
bot.user.setStatus('online')
bot.user.setActivity("en développement")
})
bot.on('message', async (msg) => {
if(msg.content.startsWith(config.prefix) && !msg.author.bot){
cmdArray = msg.content.substring(config.prefix.length).split(" ");
cmd = cmdArray[0];
args = cmdArray.slice(1);
let command = commands.getCommand(cmd);
if(command) command.run(bot, msg, args);
if(cmd === '8ball'){}
}
})
bot.login(config.token)
Instead of using "('/commande/$(files)')" use "('./commande/${files}')".
What i mean is to use ${files} instead of $(files).
Related
I trying to deploy my contract using node. I am following a youtube tutorial https://www.youtube.com/watch?v=3oaJynB0nKc&list=PLzb46hGUzitDd39YzB1YvZqeIXXtmBrHX&index=26.
I'm following everything according to this tutorial but every time I run "node deploy.js", I either get timeout error: (Note I am not using any truffle framework yet.)
process["on"]("unhandledRejection", function (reason) { throw reason; });
^
Error: Failed to check for transaction receipt:
{}
at Object._fireError (C:\Users\schit\Desktop\Solidity Dapp\inbox\node_modules\web3-utils\lib\index.js:49:17)
at C:\Users\schit\Desktop\Solidity Dapp\inbox\node_modules\web3-core-method\lib\index.js:246:23
My code is as follows:
const HDWalletProvider = require('#truffle/hdwallet-provider');
const Web3 = require('web3');
const interface = require('./compile.js');
let abi = interface.abi;
let bytecode = interface.bytecode;
var mnemonic = '12-word mnemonic';
var endpoint = 'https://ropsten.infura.io/v3/<key>';
const provider = new HDWalletProvider({
mnemonic: {
phrase: mnemonic
},
providerOrUrl: endpoint
});
console.log('********DEBUG*LOG**********2');
const options = {
transactionConfirmationBlocks: 1
};
const web3 = new Web3(provider, null, options);
console.log('********DEBUG*LOG**********3')
const deploy = async () => {
const accounts = await web3.eth.getAccounts();
var balance = await web3.eth.getBalance(accounts[0]);
console.log('Account balance: ', web3.utils.fromWei(balance, "ether"));
console.log('Attempting to deploy from account', accounts[0]);
var contract = new web3.eth.Contract(abi);
**const result = await contract
.deploy({data: '0x' + bytecode, arguments: ['Hi there!']})
.send({from: accounts[0], gas: '1000000'})
.on ('error', console.error)
.on ('transactionHash', console.log)
.on ('receipt', console.log);**
console.log('Contract deployed to', result.options.address);
};
deploy();
I'm was trying to use "gmail-tester" library to verify the account creation message.
https://www.npmjs.com/package/gmail-tester
It seems that I settled up everything as it was supposed to be done. When my test is finished I supposed to get an assertion in cypress such as this
Instead, cypress is awaiting for a message for 30seconds
, then browser crashes and I got this
Does anyone know what would cause the problem?
I have managed to complete all steps mentioned in this tutorial:
https://levz0r.medium.com/how-to-poll-a-gmail-inbox-in-cypress-io-a4286cfdb888
../cypress/plugins.index.js
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* #type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
const path = require("path");
const gmail = require("gmail-tester");
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
// ...
on("task", {
"gmail:check": async args => {
const { from, to, subject } = args;
const email = await gmail.check_inbox(
path.resolve(__dirname, "credentials.json"), // credentials.json is inside plugins/ directory.
path.resolve(__dirname, "gmail_token.json"), // gmail_token.json is inside plugins/ directory.
subject,
from,
to,
10, // Poll interval (in seconds)
12 // Maximum poll interval (in seconds). If reached, return null, indicating the completion of the task().
);
return email;
}
});
};
testCase.spec.js
import Navigation from '../../../utils/navigation.spec'
import LoginPage from '../../../pageobject/login/login-page'
describe("New user registration", async function() {
beforeEach(() => {
cy.visit(Navigation.Login)
})
it.only("Reset Form: Email is delievered", function() {
const test_id = new Date().getTime();
const incoming_mailbox = `userautomatedtest+${test_id}#gmail.com`;
// const password = uuidv1().split("-")[0];
const login = new LoginPage();
const username = "Cypress" + test_id;
const password = "111#wZOO";
login.registerButton()
.usernameInput(username)
.emailInput(incoming_mailbox)
.firstNameInput("Name")
.lastNameInput("Surname")
.passwordInput(password)
.repeatPasswordInput(password)
.registerButton()
//assert
cy.contains('Registration succeeded').should('be.visible')
cy.task("gmail:check", {
from: "dev.mailer.no.reply#gmail.com",
to: incoming_mailbox,
subject: "Registration confirmation"
})
.then(email => {
assert.isNotNull(email, `Email was not found`);
});
});
});
btw: in documentation is mentioned that by changing this number we can manipulate awaiting time for checking email. In my case, I'm changing this value and nothing is happening.
This is some problem with the OAuth consent screen, probably access given is not correct, or the GMail API isn't enabled.
Using the most recent version of this package, I had the same issue with the plugins/index.js crashing.
I solved this by adjusting the options-parameter to match the gmail task package function check_inbox.
module.exports = (on, config) => {
on("task", {
"gmail:check": async (args) => {
const { from, to, subject } = args;
const email = await gmail.check_inbox(
path.resolve(__dirname, "credentials.json"),
path.resolve(__dirname, "gmail_token.json"),
{
subject: subject,
from: from,
to: to,
wait_time_sec: 10,
max_wait_time_sec: 30,
}
);
return email;
},
});
};
I am trying to fill a pdf form using nodejs.
Im trying to use node-pdftk package for the same.Did following steps:
Installed pdftk for windows
mapped the path to the environment variables PATH
installed node-pdf package
`const express = require('express')
const app = express()
const cors = require('cors')
const pdftk = require('node-pdftk');
const bodyParser = require('body-parser');
var multer = require('multer'); // v1.0.5
var upload = multer();
app.listen(8000, () => {
console.log('Server started!')
});
var pdfPath='OoPdfFormExample.pdf';
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));
var formdata = {
'Given Name': 'Swetha',
'Family Name': 'Gulapannavar'
}
app.post('/api/file', upload.array(), (req, res, next) => {
//var buffer=JSON.stringify(Buffer.from(req.body));
var buffer=Buffer.from(req.body)
pdftk
.input(pdfPath)
.fillForm(formdata)
.flatten()
.output()
.then(buffer => {
// Still returns a buffer
res.type('application/pdf'); // If you omit this line, file will
download
res.send(buf);
})
.catch(err => {
res.send(err.message)
// handle errors
});
});`
but i'm getting following error when i try to execute the same.
Write EPIPE error.
This could be caused by node-pdftk not being able to find the PDFtk binaries; your PATH variable may not be set correctly for the account running your web service. You can set the bin path directly inside of your application using node-pdftk's configure function, which is briefly described on the node-pdftk npm project page. If that doesn't work, try configuring the tempDir path.
Suppose we have the following command line to run a json-server (https://github.com/typicode/json-server):
json-server db.json --routes routes.json --port 8008 --delay 1000
If we were to run json-server as a module, how do we set these options? I can see the db.json defined and the port defined. But it is not clear how the rest of the options can be defined.
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middleWares = jsonServer.defaults();
server.use(middleWares);
router.render = (req, res) => {
console.log(req);
};
server.use(router);
server.listen(8008, () => {
console.log('JSON Server is running');
});
I found how to set the delay. This requires installing the connect-pause package, which is also used in the json-server code (https://www.npmjs.com/package/connect-pause):
npm install connect-pause
Then on the server.js file, I added the following a require('connect-pause') and used it in the json server app. Here is my code:
const fs = require('fs');
const pause = require('connect-pause');
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();
server.use(middlewares);
server.use(jsonServer.bodyParser);
//
// Define custom routes (routes.json)
//
var routes = JSON.parse(fs.readFileSync('routes.json'));
server.use(jsonServer.rewriter(routes));
...
server.use(pause(1000));
server.use(router);
server.listen(8008, () => {
console.log('JSON Server is running');
});
To set any other option varies wildly, but I mainly needed to know how to set the delay.
I've downloaded a repository from Git to make amendments to it however, I can't seem to compile it and make it run.
I was prompted to install node modules, #ionic/cli-pl
ugin-gulp and also #ionic/cli-plugin-ionic1 as this was an ionic1 based project.
I keep receiving this error:
C:\Users\User1\Desktop\belfastsalah-master\belfastsalah-master\node_modules\#ionic\cli-plugin-ionic1\dist\serve\live-reload.js:19
let contentStr = content.toString();
^
TypeError: Cannot read property 'toString' of undefined
at Object.injectLiveReloadScript (C:\Users\User1\Desktop\belfastsalah-master\belfastsalah-master\node_modules\#ionic\cli-plugin-ionic1\dist\serve\live-reload.js:19:29)
at ReadFileContext.fs.readFile [as callback] (C:\Users\User1\Desktop\belfastsalah-master\belfastsalah-master\node_modules\#ionic\cli-plugin-ionic1\dist\serve\http-server.js:59:39)
at FSReqWrap.readFileAfterOpen [as oncomplete] (fs.js:366:13)
Below is the code from the JS file the error appears in however, this hasn't been modified by me. It is what I was prompted to install as stated above.
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const modules_1 = require("../lib/modules");
function createLiveReloadServer(options) {
const tinylr = modules_1.load('tiny-lr');
const liveReloadServer = tinylr();
liveReloadServer.listen(options.livereloadPort, options.address);
return (changedFiles) => {
liveReloadServer.changed({
body: {
files: changedFiles.map(changedFile => ('/' + path.relative(options.wwwDir, changedFile)))
}
});
};
}
exports.createLiveReloadServer = createLiveReloadServer;
function injectLiveReloadScript(content, host, port) {
let contentStr = content.toString();
const liveReloadScript = getLiveReloadScript(host, port);
if (contentStr.indexOf('/livereload.js') > -1) {
return content;
}
let match = contentStr.match(/<\/body>(?![\s\S]*<\/body>)/i);
if (!match) {
match = contentStr.match(/<\/html>(?![\s\S]*<\/html>)/i);
}
if (match) {
contentStr = contentStr.replace(match[0], `${liveReloadScript}\n${match[0]}`);
}
else {
contentStr += liveReloadScript;
}
return contentStr;
}
exports.injectLiveReloadScript = injectLiveReloadScript;
function getLiveReloadScript(host, port) {
if (host === '0.0.0.0') {
host = 'localhost';
}
const src = `//${host}:${port}/livereload.js?snipver=1`;
return ` <!-- Ionic Dev Server: Injected LiveReload Script -->\n` + ` <script src="${src}" async="" defer=""></script>`;
}
Any help would be greatly appreciated.
Thanks
You should check if, after all bundling/generation is done, www/index.html exists
Had this problem after extensive experiments with index.html generation what resulted with it being gone ;)