Answer the question
In order to leave comments, you need to log in
How to include styles in node.js?
There is add.html:
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8" />
<title>Add new user</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" >
<link rel="stylesheet" href="/css/style.css" type="text/css" />
</head>
<body>
<div id="form" class="b_form">
<form action="/register" method="POST">
<div class="f_item f_title">Add USER</div>
<div class="f_item"><input type="text" name="uName" placeholder="Enter your name" value=""></div>
<div class="f_item"><input type="text" name="uLogin" placeholder="Enter your login" value=""></div>
<div class="f_item"><input type="submit" value="Submit"></div>
</form>
</div>
</body>
</html>
const express = require("express"),
path = require("path"),
bodyParser = require("body-parser");
const app = express();
const urlencodedParser = bodyParser.urlencoded({extended: false});
app.use(express.static(__dirname + '/public'));
app.post("/register", urlencodedParser, function (request, response) {
if(!request.body) return response.sendStatus(400);
console.log(request.body);
response.send(`${request.body.uName} - ${request.body.uLogin}`);
});
app.get("/", function(request, response){
response.send("<h1>Главная страница</h1>");
});
app.get('/register', function(req, res) {
res.sendFile(path.resolve(__dirname, 'register.html'));
});
app.listen(3000);
Answer the question
In order to leave comments, you need to log in
If the file is in the root, then:
<link rel="stylesheet" href="css/style.css" type="text/css" />
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question