Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Your First Route | Section
/
Building APIs with Express.js

bookYour First Route

メニューを表示するにはスワイプしてください

A server becomes useful when it can respond to requests. In Express, this is done using routes.

A route defines what should happen when a user accesses a specific URL.

const express = require('express');

const app = express();

app.get('/', (req, res) => {
  res.send('Hello from server');
});

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

Here, app.get() defines a route for the '/' path. This path represents the homepage.

When a user opens http://localhost:3000, the server runs the function and sends a response using res.send().

The req object represents the incoming request, and the res object is used to send a response back.

Now your server not only runs but also responds to requests.

question mark

What does res.send() do?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  3

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  3
some-alt