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 Express Basics Getting Started with Express Adding Multiple Routes to the App

ReferenceError: request is not defined

Has anyone encountered the error 'ReferenceError: request is not defined' when trying to follow the get method example?

I've tried assigning it to a required variable (eg 'const request = require('request');') but this returns the error 'Error: Invalid protocol: http'

Code below:

const express = require('express'); const request = require('request'); // not in video, added in response to the error 'request is not defined'

const app = express();

app.get('/', request, response => { response.send('I love Treehouse!'); });


2 Answers


I guess there is no need to require request as module seperately. The request and response are default parameters of get callback execution.

app.get('/', (request, response) => { response.send('I love Treehouse!'); });

Add brackets as well.


Thanks again Ashish!

I was just going through the Express documentation and realised the brackets were missing rolls eyes