app.listen(port, callback)
listens for connections on the given path.
import express from "express";
const PORT = 4000;
const app = express();
const handleListening = () =>
console.log(`Server listenting on port http://localhost:${PORT}`);
app.listen(PORT, handleListening);
app.get(path, callback [, callback ...])
Routes HTTP GET requests to the specified path with the specified callback functions.
app.get("/", (req, res) => res.send("<h1>Home</h1>"))
app.use([path,] callback [, callback...])
Mounts the specified middleware function or functions at the specified path: the middleware function is executed when the base of the requested path matches path.
const callback = (req, res, next) => {
console.log(`Path: ${req.url}`);
next();
};
app.use(callback)
app.get("/", handleHome);
const callback = (req, res, next) => {
console.log(`Path: ${req.url}`);
next();
};
app.get("/", callback, handleHome);
app.use(express.static('public'));
app.use('/static', express.static('public'));
자료 출처
https://expressjs.com/