Board logo

標題: nodejs 新手問題.... [打印本頁]

作者: 專業收買佬    時間: 2017-11-11 22:41     標題: nodejs 新手問題....

server.on('connection', function(client){
   templist.push(client);
   if (!isLoaded){
       send_period();
       isLoaded=true;
   }

   function send_period(){
       setTimeout(function () {
           var count = server.getConnections();
           var new_date = new Date();
           var new_time = new_date.getTime();
           console.log("Duration=" + (new_time - time) +"ms");
           time = new_time;
           console.log("There is / are " + count + " connections.");
           send_period();
       }, 10000);
   }
作者: 專業收買佬    時間: 2017-11-11 22:41

internal/process/next_tick.js:142
      throw new TypeError('callback is not a function');
      ^

TypeError: callback is not a function
    at process.nextTick (internal/process/next_tick.js:142:13)
    at end (net.js:1474:13)
    at Server.getConnections (net.js:1478:12)
    at Timeout._onTimeout (C:\Users\Kevin\WebstormProjects\untitled1\taxi.js:32:31)
    at ontimeout (timers.js:386:11)
    at tryOnTimeout (timers.js:250:5)
    at Timer.listOnTimeout (timers.js:214:5)

Process finished with exit code 1
作者: 專業收買佬    時間: 2017-11-11 22:42

請問我衰左D咩.....
似乎應該係有D好簡單的野衰左.....但我又完全諗唔明...
作者: kin021360    時間: 2017-11-11 23:41

https://nodejs.org/api/net.html# ... onnections_callback
請睇doc
.getConnections()係async function 要放callback function去拎個count
作者: 專業收買佬    時間: 2017-11-12 00:03

請睇doc
.getConnections()係async function 要放callback function去拎個count
kin021360 發表於 2017-11-11 23:41



    感激不盡......

估唔到係咁....
順便請問多句....我用緊webStorm....但感覺好似唔多好用...
有無D更好的IDE....
作者: kin021360    時間: 2017-11-12 00:13

感激不盡......

估唔到係咁....
順便請問多句....我用緊webStorm....但感覺好似唔多好用...
有 ...
專業收買佬 發表於 2017-11-12 00:03


WebStorm已經好好用嫁啦........(而且唔係免費
我自己寫js都係用WebStorm(有student license), 係公司先焗住用Visual Studio Code
WebStorm>Visual Studio Code(free)>eclipse(free)

WebStorm有咩唔好?
定你未試用過其他IDE?
作者: 專業收買佬    時間: 2017-11-12 00:43

WebStorm已經好好用嫁啦........(而且唔係免費
我自己寫js都係用WebStorm(有student license),  ...
kin021360 發表於 2017-11-12 00:13



    無試過其他.....上網search之後就dl黎裝...
覺得佢唔好係因為我唔識寫nodejs....
成日寫錯野但webstorm唔識話我錯...
要到run時先彈我......
作者: 梁炳    時間: 2017-11-12 00:52

Visual Studio Code
作者: kin021360    時間: 2017-11-12 02:10

無試過其他.....上網search之後就dl黎裝...
覺得佢唔好係因為我唔識寫nodejs....
成日寫錯野但webst ...
專業收買佬 發表於 2017-11-12 00:43


本身javascript係weak type language冇Java, C個d咁嚴格 冇計(轉學Type script?)
而係javascript既角度: variable冇type 可以任你轉, function有parameter你唔pass野落去又唔算錯
仲有== vs ===同!= vs !== 你最好google下有咩分別

最好開頭加"use strict";
用let同const取代var
作者: 專業收買佬    時間: 2017-11-12 02:25

本身javascript係weak type language冇Java, C個d咁嚴格 冇計(轉學Type script?)
而係javascript既角度:  ...
kin021360 發表於 2017-11-12 02:10



    我都覺javascript好多地雷.....

多謝賜教....





歡迎光臨 電腦領域 HKEPC Hardware (https://www.hkepc.com/forum/) Powered by Discuz! 7.2