javascript – Display a variable from a JS file to another JS file

I program a simple Twitter BOT in Node.js and I need to display variables and external data and display them in my main file called bot.js (below what it contains)

I have a file called botele.js which is where the external variable to display in my hand..which has this code is found ..

var unirest = require("unirest");
var req = unirest("GET", "https://xxxx");

	"x-rapidapi-host": "xx",
	"x-rapidapi-key": "xxx"

req.end(function (res) {
	if (res.error) throw new Error(res.error);


The response is as follows:

results: ({id: 244, idSeason: 436, name: & # 39; Regular Season & # 39;}),
page 1,
itemsPerPage: 20

And then I have another JS file called bot.js which is responsible for posting the tweet, where ..

 const config = require('./config')
 const datasport = require('./botele')
 const twit = require('twit')
 const T = new twit(config)
    { status: 'Prueba' },
    (err, data, response) => {
      console.log(err, data, response);

Basically what I want is to display the name of the variable generated by the botele.js file in my main bot.js file, more exactly in the state of the bot.js code … is -it's possible?

javascript – readFileSync returns undefined when trying to read data from files

I have created several functions under a directory called data and fill them with random data returned by a function called generatedRandomData.
To create multiple files, I wrote these functions:

const createFile = (fileName, data) => {
  if (fs.existsSync(fileName)) throw new Error('Filename already exists');
  fs.writeFile(fileName, data, {
    encoding: 'utf8',
    flag: 'w',
  }, (error) => {
    if (error) return error;
    console.log('File created successfully');
    return null;

const createFiles = (dirPath, sizeList) => {
  if (sizeList && !sizeList.length) throw new Error('The list of size should not be empty');

  const fileCreationPromises = (size) => {
    const data = generateRandomData(size);
    const fileName = resolve(dirPath, `./data_${size}.txt`);
    await createFile(fileName, data);
  return Promise.all(fileCreationPromises);

Then I call the function generateData in order to generate random data and call the functions described above and then create the files:

const generateData = async (dirPath, sizeList) => {
  if (!dirPath) throw new Error('No directory path was provied');
  if (!sizeList || (sizeList && !sizeList.length)) throw new Error('Size list should not be empty');
  await createFiles(dirPath, sizeList);

I call another function called execute which reads the data from these files in order to continue processing:

const execute = async (func, dirPath, label) => {
  const files = fs.readdirSync(dirPath);
  const result = ();
  if (files && files.length) {
    for (const file of files) {
      const filename = resolve(dirPath, `./${file}`);
      const parsedData = readDataFromFile(filename);
      const data = parsedData.split(',').map((d) => Number(d));
      const { length } = data;

        label: length,
        value: getExecutionTime(func, data),
  await createFile(resolve(dirPath, `./${label}`));

Finally, I call the function initialize:

const { resolve } = require('path');
const fs = require('fs');
const { generateData, sizeList, execute } = require('../utils/helpers');
const { underscorePartial } = require('../main/partial');

const dirPath = resolve(__dirname, '../data');

const initialize = () => {
  if (!fs.existsSync(dirPath)) {
    fs.mkdir(dirPath, async (error) => {
      if (error) throw error;
      await generateData(dirPath, sizeList);
      await execute(underscorePartial, dirPath, 'uExecutionTime.txt');

try {
} catch (error) {

But I realized that uExecutionTime.txt to create in the final step contains undefined because of the function readDataFromFile that comes back undefined.
I guess the readDataFromFile start reading files before data creation is complete. Any suggestions for correcting my code or is there something missing or incorrect in the code?

Problem with CSS animation called by javascript function

Well guys, I have the following situation. I have an index.html page which contains one which is updated via a WebSocket using javascript. Each time the server sends the message to update the value, the update (value) function is called:

function atualizar(valor){
    document.getElementById("valor").innerText = valor;
    document.getElementById("valor").style.animation = "example 1s 1";


 #valor {
     color: #FFFFFF;
     font-family: "Trebuchet MS", Arial;
     margin-top: 5px;
     font-size: 36px;
     font-weight: bold;

@keyframes example {
   50%   {font-size: 45px;}
   100%  {font-size: 36px;}
   10%, 90% {
       transform: translate3d(-1px, 0, 0);

   20%, 80% {
       transform: translate3d(2px, 0, 0);

   30%, 50%, 70% {
       transform: translate3d(-4px, 0, 0);

   40%, 60% {
      transform: translate3d(4px, 0, 0);

As you can see, the idea is that when updating the value, this creates an effect of scale and agitation with the text.

The problem is that it only works the first time the function is called, so it no longer works. In Javascript and CSS, I'm a layman haha. If anyone can help me, thank you in advance!

javascript – Cannot add two scripts

I am trying to add two scripts to the header of my site. I can install only one script, like this:

I can't add two scripts, like these:

I have tried the following techniques and all of them produce an error:

  • Plugin header and footer scripts
  • Plug-in insertion headers and footers
  • Genesis Simple Hooks Plugin
  • Theme customizer (Appearance -> Personalize -> Theme settings -> Header / footer scripts)
  • Edit the theme functions.php file using Appearance -> Theme Editor like this:
                add_action (& # 39; wp_head & # 39 ;, & # 39; your_function_name0 & # 39;);
function your_function_name0 () {
    <? php

The only way I have found to add two scripts is to edit the functions.php file externally and then upload it to my server.

There may be some kind of validation in progress. I notice that I can't add a single script if I don't specify the type attribute or if i enter a

I have tried to disable all plugins by renaming the plugins directory on the file system. This did not solve the problem.

javascript – How to change the tabs in materialize without using JQuery?

To reach the navigation between tabs And don't depend on using JQuery so let's first get the tag from the messy list across the class which is assigned this way:

let tabs = document.querySelector(".tabs")

The method document.querySelector() It allows us to recover the node which we indicate either by its name, or by its id, or by the class which is assigned to it.

Based on the documentation, we then pass the variable in which we store the method described above as the first argument.

let instance = M.Tabs.init(tabs);

Complete example from the documentation 1

      JS Bin
Test 1
Test 2
Test 3
Test 4


ajax – Save the value of the Javascript object to the WP user

This is a follow-up to this post. I work with a service that automatically registers my users' devices with Onesignal.

I call the function with gonative_onesignal_info () inside script tags (this registers devices perfectly with Onesignal):

function pmr_onesignal_script () {?>


<? php

add_action (& # 39; wp_head & # 39 ;, & # 39; pmr_onesignal_script & # 39 ;, 10, 2);

Inside register-user.php I have this:

function pmr_onesignal_mobile_registration( $user_login, $user ) {

    // Get user data
    $user_id = $user->ID;
    $user_email = $user->user_email;

    $oneSignalPushToken = $_GET('oneSignalPushToken');
    update_user_meta( $user_id, 'oneSignalPushToken', $oneSignalPushToken);

add_filter( 'wp_login', 'pmr_onesignal_mobile_registration', 10, 2 );

However, it appears that the oneSignalPushToken is never actually pushed into the file, and this is never saved to the user. Any ideas on what I could do wrong here? Thanks in advance!

javascript – Automatically execute a function in the google script when a new line is added to the google sheet

From my spreadsheet script editor, I use a script to submit data (emails) to the spreadsheet.

In the sheet, I have two tabs:

Sheet1: receives new submitted emails

Sheet2: sorts the emails in Sheet1 in reverse order according to the Timestamp column, so all the time in Sheet2, I have the last email sent in cell B2

I added the function below to the script to allow me to send an email to the address located in Sheet2, cell B2

function SendEmail() {
var e = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet2").getRange("B2").getValues();
var m = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet3").getRange("A1").getValues();
var subject = 'Welcome to ..';
MailApp.sendEmail(e, subject, m);


The problem is: the SendEmail function only works well when I execute the function manually from the script and I want it to execute automatically once a new line is submitted leaf

I have tried to add triggers in two ways:

First of all, as we know, the sheet is preset to 1000 lines by default, so I deleted all the blanks, then triggers from the current project, I added the OnChange trigger. I thought that when the total number of lines is changed, the trigger will work and execute the SendEmail function (but nothing happened)

Second, I tried to add a new function to the script to do the first try, but programmatically as follows:

function onChange(e) {
var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");

No luck so any help would be greatly appreciated. Thanks in advance

Full number with "zeros" until the total size is 9 (JAVASCRIPT)!

I receive a number by parameter .. ex: 18 and I must complete it with "zeros" until the total size is 9 numbers .. the result would be 180000000.

if the value received is for example 678, the result would be 678000000.

let number = 18;
let count = number.toString().length;

for (let i = count; i < 9; i++) {
  number = number.toString() + '0';

number = parseInt(number);


I managed to solve it in the following way, is there an easier way to do the same algorithm? Thank you!

javascript – Pass an array of states from one component to another in React

i have a saved() array in my component. I want to pass this data from one component to another.

I have tried the following:

But it throws an error as it says TypeError: Unable to read the "saved" property of null

It is therefore the component that has its data.


import React, { Component } from 'react';
import '../news-main/news-main.css';
import News from '../news/news';
import NewsHero from '../news-hero/news-hero';
import Sports from '../sports/sports';

class NewsMain extends Component {
    render() {
        return (
) } } export default NewsMain;

The data come from NewsHero /> component.


import React, {Component} from & # 39; react & # 39 ;;
import & # 39; ./ news-hero.css & # 39 ;;
import the "react-multi-carousel" carousel;
import "react-multi-carrousel / lib / styles.css";

const responsive = {
superLargeDesktop: {
breakpoint: {max: 4000, min: 3000},
items: 1,
desktop computer: {
breakpoint: {max: 3000, min: 1024},
items: 1,
Tablet: {
breakpoint: {max: 1024, min: 464},
items: 1,
mobile: {
breakpoint: {max: 464, min: 0},
items: 1,

NewsHero class extends component {
state = {
loading: false,
The data: (),
big title: (),
checked in: ()

saved = title => {
this.setState (
(prevState) => ({saved: (... prevState.saved, headline)}),
() => {
console.log (& # 39; Recorded articles = & # 39 ;, this.state.saved);
alert (“saved item”);
localStorage.setItem (& # 39; saved & # 39 ;, JSON.stringify (this.state.saved));
localStorage.getItem (& # 39; saved & # 39;);

manufacturer (accessories) {
super (accessories)
this.saved = this.saved.bind (this)

onError () {
this.setState ({
imageUrl: "../assets/img-error.jpg"

componentDidMount () {
this.setState ({load: true, saved: localStorage.getItem (& # 39; saved & # 39;)? JSON.parse (localStorage.getItem (& # 39; saved & # 39;)): ()})
fetch (& # 39; https: // q = timbaland & domains =, & excludeDomains = & apiKey = 8ee8c21b20d24b37856fc3ab1e22a1e5 & # 39;)
.then (headline => headline.json ())
.then (headline => this.setState ({headline: headline.articles, loading: false}, () => console.log (headline.articles))))

render () {

come back (


{this.state.loading ? "loading..." :
{ ((post, indx) => { come back (
Alternative text

{article title}

{} Post.description

Read more
) })}
) } } export NewsHero by default;

I want to pass the saved array to other components, for example


import React, { Component } from 'react';
// import logo from './logo.svg';
import './App.css';
import Header from './header/header';
import NewsMain from './news-main/news-main';
import Footer from './footer/footer';
import Home from './home/home';
import { Router } from '@reach/router';

class App extends Component {

  render() {
    return (
) } } export default App;


javascript – I don't see the digital clock

Hello, I'm doing an exercise and I can't see the digital clock that I inserted in the code, please, can you help me.
Thank you so much.