From the course: JavaScript: Test-Driven Development (ES6)

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Implementing a server endpoint

Implementing a server endpoint - JavaScript Tutorial

From the course: JavaScript: Test-Driven Development (ES6)

Start my 1-month free trial

Implementing a server endpoint

- [Man] So if we run our tests now, we'll see that the test we just wrote fails, and it should since the server we're testing doesn't even exist yet. So, lets open up our server.js file, and we're going to create an express server like this. Lets start by importing express, import express from express, and then we're going to say const app = express. That's how you create a server in express, and finally at the bottom of our file, we're going to say export app, so that our tests can actually import it. And if we re-run our tests now, we see that this test will still fail, but for a different reason. The reason that we're getting this message thing that our server returned, a 404, is that we haven't added our endpoint to our server yet, so this is exactly what we'd expect to happen. So lets add our endpoint now, and that's going to look like this. We're going to say app.get, and then /users/:username. If you haven't…

Contents