如何在数字海洋上部署 express 服务器 api

how to deploy express server api on digital ocean

我在数字海洋上有一个 ubuntu 水滴,我正在尝试部署一个 nodejs/express api。我使用 this tutorial 制作了 api,它在我的本地机器 (MacOS) 上运行良好。但是,当我尝试在我的 Droplet 上启动服务器时,出现此错误:

> node-mongo-registration-login-api@1.0.0 start /opt/loginAPI
> node ./server.js

/opt/loginAPI/_helpers/jwt.js:18
async function isRevoked(req, payload, done) {
      ^^^^^^^^

SyntaxError: Unexpected token function
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/opt/loginAPI/server.js:6:13)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-mongo-registration-login-api@1.0.0 start: `node ./server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-mongo-registration-login-api@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/treetop/.npm/_logs/2019-04-26T18_59_02_737Z-debug.log

如有任何帮助或建议,我们将不胜感激

您在同一行上有关键字 asyncfunction,解释器抱怨意外的单词 function,这意味着它可以处理单词 async,但是它不能识别 async function 在一起。我保证您本地的 Node 版本为 8+,而您的远程服务器上的版本低于 8。 Node.js 此类版本没有关键字 async(因为它本身不支持 async/await),因此它会将其视为变量或 属性 global 对象。当然它无法弄清楚,为什么你在那之后使用关键字 function 并退出 :)

P.S。请记住,Node 8 LTS 很快就会结束。