2016-11-23 96 views
0

當我在我的機器上運行我的node.js服務器時,它工作得很好。但是,當我從一個數字海洋中獲得一臺機器時,它會拋出這個錯誤。我使用飛行計劃將我的文件移動到機器上。Node.js Express Server不能在不同的服務器上工作,但在我的機器上工作

[email protected]:~/node-app/bin$ node www 

/home/deploy/node-app-1479873242669/routes/index.js:76 
         [newValue]: { 
         ^
SyntaxError: Unexpected token [ 
    at Module._compile (module.js:439:25) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 
    at Function.Module._load (module.js:312:12) 
    at Module.require (module.js:364:17) 
    at require (module.js:380:17) 
    at Object.<anonymous> (/home/deploy/node-app-1479873242669/app.js:36:18) 
    at Module._compile (module.js:456:26) 
    at Object.Module._extensions..js (module.js:474:10) 
    at Module.load (module.js:356:32) 

這是有關錯誤代碼:

  if (isNaN(value)) { 
       newValue = 0; 
       console.log("queuer val " + newValue); 
       fbRef.update({ 
        [newValue]: { 
         [UID]: ID 
        } 
       }); 
      } 

就像我說的,這工作完全正常我的機器上。謝謝!

+0

您的液滴可能安裝了不支持ES6語法的舊版節點。你可以用'node -v'來檢查。支持這種特定語法的第一個節點版本是node v4.0.0。 – mscdex

回答

1

更新節點到最新版本:

wget -qO- https://deb.nodesource.com/setup_6.x | sudo bash - 
sudo apt-get -y install nodejs 

後,應該工作。

1

使用計算密鑰創建對象是ES2015 Standard(ES6)的一部分。見Object Initializer spec

你的情況,香草JavaScript不支持此:

[newValue]: { 
    [UID]: ID 
} 

那麼可能是你的node -v將上面的東西v6.0.0,但其他的服務器將是一箇舊版本。 更新節點版本或使用帶預設的babel-node

相關問題