Your 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.
すべて明確でしたか?
フィードバックありがとうございます!
セクション 1. 章 3
AIに質問する
AIに質問する
何でも質問するか、提案された質問の1つを試してチャットを始めてください
セクション 1. 章 3