nomanHasan / todo-api

A simple todo API made with NodeJS, ExpressJS and MongoDB. Can be used as a back-end for learning front-end technologies without making a standalone API for that purpose.
26 stars 22 forks source link

Issue running todo-api #1

Open staminna opened 6 years ago

staminna commented 6 years ago

I cloned the repo and ran npm install. [nodemon] startingnode ./bin/www` /webapp/todo-api/controllers/todos.controller.js:6 exports.getTodos = async function(req, res, next){ ^^^^^^^^

SyntaxError: Unexpected token function at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:373:25) at Object.Module._extensions..js (module.js:416:10) at Module.load (module.js:343:32) at Function.Module._load (module.js:300:12) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at Object. (/Users/jorge/webapp/json_api_assets/todo-api/routes/api/todos.route.js:5:22) at Module._compile (module.js:409:26) at Object.Module._extensions..js (module.js:416:10) [nodemon] app crashed - waiting for file changes before starting...`

redkarsanket commented 6 years ago

I am also getting the same error. Which Node.js version you are using? Author mention in his article that "Another important point — We won’t be using callbacks, We even won’t be using traditional Promises. We are going to use the great async-await feature introduced in NodeJS 7.6."

So i think this may be the problem with Node.js version. I have Node.js 6.10.0 on my machine.

staminna commented 6 years ago

I am using Node.js v8.0

nomanHasan commented 6 years ago

@redkarsanket Yes you're right, It won't work on NodeJS versions prior to 7.6 .

@staminna Have you followed all these steps ?

It should be working fine after this.

Are you sure you're using the correct NodeJS version ?

The error unexpected token function <- Means that NodeJS can't recognize the token async function there, Which usually happens because the NodeJS version doesn't support async-await. Please run a node --version to see which version you're using.

If it's still showing 8.0, You can try reinstalling the latest NodeJS.

staminna commented 6 years ago

Installing at least node 8.1.4 worked for me @redkarsanket, though now there is another issue. Will open new one.

rfnbnkr commented 5 years ago

Hi. i using node v8.12.0 and when run npm install command i get bellow error added 216 packages from 120 contributors and audited 374 packages in 10.655s found 19 vulnerabilities (12 low, 2 moderate, 5 high) runnpm audit fixto fix them, ornpm auditfor details