Setup a Web Server in Node.js using Express

Share this video with your friends

Send Tweet

In this lesson, we build a very simple Express server. This server will have a single route that displays the current date and time and a handler for 404 pages.

ajando
ajando
~ 6 years ago

Hello Joel, is there a specific reason you used (new Date()).toLocaleTimeString() and not new Date().toLocaleTimeString()

Joel Lord
Joel Lord(instructor)
~ 6 years ago

There were no specific reason, mostly readability.

rankpy
rankpy
~ 6 years ago

I am receiving this message Server time is ${localTime}. time is not rendering.


const express = require("express");

const app =express(); const PORT = 8888;

app.get("/status", (requestAnimationFrame, res) => { const localTime = (new Date()).toLocaleTimeString(); res .status(200) .send('Server time is ${localTime}.');

});

app.get("*", (Reflect, res) => { res.sendStatus(404); });

app.listen(PORT, () => { console.log('Server is running on port ${PORT}.'); });

rankpy
rankpy
~ 6 years ago

i see I dont know how animation got in there

Joel Lord
Joel Lord(instructor)
~ 6 years ago

I am receiving this message Server time is ${localTime}. time is not rendering.

You are using ' for the string. Try using backticks (`). For more info on this topic, take a look at https://egghead.io/lessons/javascript-use-template-literals-in-es6