Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

process._tickCallback error. Undefined is not a function #7296

Closed
sneurgaonkar opened this issue Jun 14, 2016 · 4 comments
Closed

process._tickCallback error. Undefined is not a function #7296

sneurgaonkar opened this issue Jun 14, 2016 · 4 comments
Labels
question Issues that look for answers.

Comments

@sneurgaonkar
Copy link

Node Version: 0.10.25
Platform: Ubuntu 14

I am new to Node.js and i am developing a simple chat app using Socket.IO. I made an index.js file and an index.html file.

My index.js files looks like this

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
process.stdin.setEncoding('utf8');
var util = require('util');
process.stdin.setRawMode( true );
process.stdin.resume();

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
});

// io.use(function(socket, next){
//   if (socket.request.headers.cookie) return next();
//   next(new Error('Authentication error'));
// });

 var txt = process.stdin.on('data', function (text) {
      process.nextTick()
     return util.inspect(text);
     });
io.on('connection', function(socket){
      socket.on('chat message', function(msg){
         console.log('message: ' + msg);
      process.stdin.on('data',function(key){
        if(key === '\u0003')
        {
          socket.emit('chat message',txt);
        }
        // process.stdout.write(key);
      });
       });
    });

http.listen(3000, function(){
  console.log('listening on *:3000');
});

here is my index.html file

<!doctype html>
<html>
  <head>
    <title>Socket.IO chat</title>
    <style>
      * { margin: 0; padding: 0; box-sizing: border-box; }
      body { font: 13px Helvetica, Arial; }
      form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
      form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
      form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
      #messages { list-style-type: none; margin: 0; padding: 0; }
      #messages li { padding: 5px 10px; }
      #messages li:nth-child(odd) { background: #eee; }
    </style>
  </head>
  <body>
    <ul id="messages"></ul>
    <form action="">
      <input id="m" autocomplete="off" /><button>Send</button>
    </form>
    <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
    <script>
      var socket = io();
      $('form').submit(function(){
        socket.emit('chat message', $('#m').val());
        $('#m').val('');
        return false;
      });
      socket.on('chat message', function(msg){
        $('#messages').append($('<li>').text(msg));
      });
    </script>
  </body>
</html>

I am trying to take value from the console and print it on the browser and vice versa. In this app the chat is between the client and the server.
When i run the index.js file i get this on the terminal

listening on *:3000

When i hit the localhost:3000 on the browser and send the message from browser to client, the messaged is received successfully but when I try to send message from server(terminal) to the client(browser) i get the following error..

node.js:415
            callback();
            ^
TypeError: undefined is not a function
    at process._tickCallback (node.js:415:13)

How can i solve this? I want to get the value from the console(server) and send it to the browser(client).

@tt-hub
Copy link

tt-hub commented Jun 14, 2016

process.nextTick() takes a callback as a parameter --> https://nodejs.org/docs/latest/api/process.html#process_process_nexttick_callback_arg.

YOu missed that out

@sneurgaonkar
Copy link
Author

@tt-hub If i add the callback to the process.nextTick() function then i get the unidentified character at the " => " part of the code.

@addaleax
Copy link
Member

If your problem is that want to use arrow functions using =>, you need to upgrade to Node v4 or Node v6 (you can download them from https://nodejs.org/). It’s probably a good idea to do that anyway.

Also, for general questions about using or installing Node.js, nodejs/help may be a better place than this.

@addaleax addaleax added the question Issues that look for answers. label Jun 14, 2016
@cjihrig
Copy link
Contributor

cjihrig commented Jun 14, 2016

@addaleax and @tt-hub are right. Closing as not an issue with Node core.

@cjihrig cjihrig closed this as completed Jun 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

4 participants