Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nodejs modules not working as expected in different devices

I am using twitter streaming api & johnny-five with some other modules http , express& socket.io with arduino uno

My script is working fine in laptop. But my production will be on a tablet. I have two tablets and both are responding differently. On hp omni tablet i am receiving following error

enter image description here

Also i have arduino-uno connected on port COM3 but its shows device connected on COM1

As far as i know this error is caused when standard firmata is not uploded in arduino. I have uploaded this program and it work fine in laptop

On Acer Tablet i am not receiving any errors program starts perfectly fine without any issues but i am not receiving tweets with twitter streaming api

I have crossed checked many times it runs perfectly fine on laptop every time i run it but gives two different issues with the tablets

Here is the code i am using

var Twitter = require('twitter');
var five = require("johnny-five");
var express = require('express')
  , app = express()
  , http = require('http')
  , server = http.createServer(app)  
  , io = require('socket.io').listen(server);

server.listen(8080);

// routing
app.use(express.static(__dirname + '/http'));
app.use(function (req, res, next) {
        res.setHeader('Access-Control-Allow-Origin', "http://"+req.headers.host+':80');

        res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
        res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
        next();
    }
);

var client = new Twitter({
  consumer_key: 'abc',
  consumer_secret: 'abc',
  access_token_key: 'abc',
  access_token_secret: 'abc'
});

var board = new five.Board();

board.on("ready", function() {
    this.pinMode(5, five.Pin.OUTPUT);
    this.pinMode(10, five.Pin.INPUT);
      //Ask to visit url
      console.log("Visit http://localhost:8080");
    var randomHashtag = Math.floor((Math.random() * 10000) +1);
    var count = 0;//Initialize counter
    io.sockets.on('connection', function (socket) {     
        console.log('Ready to recieve tweets');//Prints Message when Socket.io is ready to recieve tweets
        io.emit('stream',{number:randomHashtag});//Send random no when socket initzilize
        client.stream('statuses/filter', {track: '#tweetMe'}, function(stream) {
            stream.on('data', function(tweet) {
                if(tweet.text.search(randomHashtag) > 0){
                    count++;//Increment pending tweets              
                    randomHashtag  = Math.floor((Math.random() * 10000) +1);                
                    io.emit('stream',{number:randomHashtag});                   
                    board.digitalWrite(5,1);
                    console.log(tweet.text);                    
                }
                else{
                    console.log("Tweet Without random No");
                }
            });

        stream.on('error', function(error) {
            throw error;
        });
        });
    });
});
like image 521
Skyyy Avatar asked Nov 28 '15 14:11

Skyyy


People also ask

Is NodeJS still relevant 2022?

Node. js development has become very popular over the last four years and continues to stand the competition in 2022 making startups worldwide choose it over other available options.

Why is NodeJS not suitable for CPU intensive work?

js receives a CPU bound task: Whenever a heavy request comes to the event loop, Node. js would set all the CPU available to process it first, and then answer other requests queued. That results in slow processing and overall delay in the event loop, which is why Node. js is not recommended for heavy computation.

How do I resolve Cannot find module error using NodeJS?

To fix the Cannot find module error, simply install the missing modules using npm . This will install the project's dependencies into your project so that you can use them. Sometimes, this might still not resolve it for you. In this case, you'll want to just delete your node_modules folder and lock file ( package-lock.

CAN NodeJS handle high traffic?

Since Node. js uses non-blocking IO, the server can handle multiple requests without waiting for each one to complete, which means Node. js can handle a much higher volume of web traffic than other more traditional languages.


1 Answers

As you said it works perfectly fine with other devices and also managed to fix issue with other tablet the possible reason i can think of is corrupt installation of nodejs or other modules you are using

Try to clean re-installation of Nodejs and all modules. May be there is some problem in your modules not in your code.

Another reason you have following issue nodejs maintain two different version both handle installing of modules a different way.

Use the same version you are using in your laptop.

like image 118
Hemant Parihar Avatar answered Nov 15 '22 01:11

Hemant Parihar