Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript REST APIs with Express Create, Read, Update, Delete Using Postman to Test Routes

Damian Szymanski
Damian Szymanski
11,843 Points

I keep getting an error using the default project files for this video

Hello! I keep getting this error when I type "node app.js" using the default files for "Using Postman to test routes"

the error:

/Users/damianszymanski/Downloads/rest_apis_express_projectfiles 2/S3V1_postman/app.js:7
app.get('/quotes', async (req, res)=>{
                         ^
SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)

Thanks! Damian.

Hello Damian Szymanski mind posting your whole app.js.

Damian Szymanski
Damian Szymanski
11,843 Points

Juan Lopez here is my app.js:

const express = require('express');
const app = express();

const records = require('./records');

// Send a GET request to /quotes to READ a list of quotes
app.get('/quotes', async (req, res)=>{
    const quotes = await records.getQuotes();
    res.json(quotes);
});
// Send a GET request to /quotes/:id to READ(view) a quote
app.get('/quotes/:id', async (req, res)=>{
    const quote = await records.getQuote(req.params.id);
    res.json(quote);
});
// Send a POST request to /quotes to  CREATE a new quote 
// Send a PUT request to /quotes/:id to UPDATE (edit) a quote
// Send a DELETE request to /quotes/:id DELETE a quote 
// Send a GET request to /quotes/quote/random to READ (view) a random quote

app.listen(3000, () => console.log('Quote API listening on port 3000!'));

Everything looks fine as far as in your app.js code. When I run node app.js or even npm start everything starts up just fine.

Maybe close out and restart your text editor?

Damian Szymanski
Damian Szymanski
11,843 Points

hmm, I tried that and it didn't work. weird.

1 Answer

Damian Szymanski
Damian Szymanski
11,843 Points

I have figured it out! my node was out of date so I had to update it. Thanks for all the help! :) -Damian.