question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best practics to use express with telegram-node-bot

See original GitHub issue

Hello! Im try to use this framework with express framework for notice users via get query from php-app. Well heres my code: `‘use strict’ const express = require(‘express’); const app = express(); app.listen(8008);

const Telegram = require('telegram-node-bot');
const TelegramBaseController = Telegram.TelegramBaseController;
const TextCommand = Telegram.TextCommand;
const tg = new Telegram.Telegram('MYTOKEN');`

So i get binded port error cause express execute many times. Some Log


Telegram Worker started at 1804 PID


[log]
Telegram Worker started at 6180 PID


[log]
Telegram Worker started at 5904 PID


[log]
Telegram Worker started at 5300 PID


events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: bind EADDRINUSE null:8008
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at cb (net.js:1324:16)
    at shared (cluster.js:619:5)
    at Worker.<anonymous> (cluster.js:592:9)
    at process.<anonymous> (cluster.js:765:8)
    at emitTwo (events.js:111:20)
    at process.emit (events.js:191:7)
    at process.nextTick (internal/child_process.js:744:12)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: bind EADDRINUSE null:8008
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at cb (net.js:1324:16)
    at shared (cluster.js:619:5)
    at Worker.<anonymous> (cluster.js:592:9)
    at process.<anonymous> (cluster.js:765:8)
    at emitTwo (events.js:111:20)
    at process.emit (events.js:191:7)
    at process.nextTick (internal/child_process.js:744:12)
    at _combinedTickCallback (internal/process/next_tick.js:67:7)

What should i do for fix this issue? Thx and sorry for bad english 😃

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
numkmscommented, May 29, 2017

`//init modules const express = require(‘express’); const port = 8888; var listener = express();

const Telegram = require(‘telegram-node-bot’) const TelegramBaseController = Telegram.TelegramBaseController const TextCommand = Telegram.TextCommand

let tg = new Telegram.Telegram(‘key’);

tg.onMaster(() => { listener.listen(port, function (){ console.log('Your app runing on '+port); });

        listener.get('/query',function(req,res){
                res.send('your response');
        });

});`
Like this

1reaction
numkmscommented, May 29, 2017

Yes i have, u need to use express init in $.onMaster callback

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a Telegram bot with Node.js and Sanity
Learn how to hook up a Telegram chatbot to Sanity using Node.js in this short, snappy tutorial.
Read more >
Building A Telegram Bot With NodeJS | by Manny - Medium
In our file, configure a simple output to return the data and just console log the payload in Terminal. index.js // Dependencies const...
Read more >
Building your First Telegram Bot using Node.js and Telegraf
In this tutorial, you will learn how to build telegram bots using Node.js runtime environment and Telegraf library from scratch.
Read more >
Building a Telegram Bot with Node.js in 10 minutes - YouTube
We are building a very basic Telegram Bot using Node.js, JavaScript and Telegram's Bot API. This tutorial will teach you to- create a ......
Read more >
How To Build a Telegram Bot With Node.js in Under 3 Minutes
Telegram is a WhatsApp alternative — in my opinion, a pretty good one. It is free to use is considered very secure. But...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found