0
0
Expressframework~10 mins

Testing GET endpoints in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the Express module.

Express
const express = require([1]);
Drag options to blanks, or click blank then click option'
A"express"
B"http"
C"path"
D"fs"
Attempts:
3 left
💡 Hint
Common Mistakes
Using other module names like 'http' or 'fs' instead of 'express'.
Forgetting to put quotes around the module name.
2fill in blank
medium

Complete the code to create a new Express application.

Express
const app = [1]();
Drag options to blanks, or click blank then click option'
Ahttp
Bexpress
Crequire
Dapp
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to call require() instead of express().
Using http() which is not the Express app creator.
3fill in blank
hard

Fix the error in the GET route handler to send a response.

Express
app.get('/hello', (req, res) => {
  res.[1]('Hello World');
});
Drag options to blanks, or click blank then click option'
Asend
Bjson
Cend
Dwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using res.write() without ending the response.
Using res.end() without sending data.
4fill in blank
hard

Fill both blanks to start the server on port 3000 and log a message.

Express
app.listen([1], () => {
  console.[2]('Server running on port 3000');
});
Drag options to blanks, or click blank then click option'
A3000
Blog
Cerror
Dinfo
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.error or console.info instead of console.log.
Passing a string instead of a number as the port.
5fill in blank
hard

Fill all three blanks to test the GET /hello endpoint using supertest.

Express
import request from 'supertest';
import app from './app';

test('GET /hello returns Hello World', async () => {
  const response = await request(app).[1]('/hello');
  expect(response.statusCode).toBe([2]);
  expect(response.[3]).toBe('Hello World');
});
Drag options to blanks, or click blank then click option'
Aget
B200
Ctext
Dbody
Attempts:
3 left
💡 Hint
Common Mistakes
Using post instead of get.
Checking response.text instead of response.body.
Expecting status code other than 200.