This project will allow you to practice setting up a server that will handle simple requests in Express.js.
You will be setting up a server with four endpoints using the Express.js framework.
The endpoints will only respond to GET requests, and send a string as a response.
- Install the express.js npm package
npm i express
- Create the file
server.js
Use the following code to setup your server
import express from "express";
const app = express();
const server = app.listen(3001, () => {
console.log("The server is listening... 🐒");
});
Create an endpoint that will respond to the path /hello
- It should send a response with a string. Use the following string;
Hello to you too!
Create an endpoint that will respond to the path /time
.
- It should return a
response
with the current time and date
Research:
Create an endpoint that will respond to the path /random
.
- It should send a response with the random number
Research:
Create an endpoint that will respond to the path /fact
.
- It should send a response with a string. Use the following string;
JavaScript was created in about 10 days!
⌛ Give it a minute. As long as you see the orange dot on top, CodeBuddy is still processing. Refresh this page to see it's current status.
This is what CodeBuddy found when running your code. It is to show you what you have achieved and to give you hints on how to complete the exercise.
Status | Check |
---|---|
server.js should exist |