DasPete
DasPete

Reputation: 851

how to deploy express server api on digital ocean

I have an ubuntu droplet on digital ocean and I'm tyring to deploy a nodejs/express api. I used this tutorial to make the api and it runs great on my local machine (MacOS). However, when I try to start the server on my droplet I get this error:

> [email protected] 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! [email protected] start: `node ./server.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] 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

Any help or advice would be greatly appreciated

Upvotes: 0

Views: 326

Answers (1)

Vladyslav Usenko
Vladyslav Usenko

Reputation: 2386

You have keywords async and function on the same line and the interpreter complains about unexpected word function, which means that it treats word async okay, but it doesn't recognize async function together. I guarantee that you have Node version 8+ locally and version less than 8 on your remote server. Node.js of such versions doesn't have a keyword async (because it doesn't support async/await natively), therefore it treats it like a variable or a property of global object. Of course it can't figure out, why you are using keyword function after that and exits :)

P.S. Keep in mind that Node 8 LTS ends very soon.

Upvotes: 1

Related Questions