用node.js写一个注册页面
时间: 2023-11-14 12:10:15 浏览: 33
好的,以下是一个简单的注册页面的示例代码:
```javascript
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const PORT = 3000;
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.get('/register', (req, res) => {
res.send(`
<html>
<head>
<title>Register</title>
</head>
<body>
<form action="/register" method="post">
<label for="username">Username:</label>
<input type="text" name="username"><br><br>
<label for="email">Email:</label>
<input type="email" name="email"><br><br>
<label for="password">Password:</label>
<input type="password" name="password"><br><br>
<button type="submit">Register</button>
</form>
</body>
</html>
`);
});
app.post('/register', (req, res) => {
const { username, email, password } = req.body;
// TODO: Save user information to database
res.send(`User registered successfully!`);
});
app.listen(PORT, () => {
console.log(`Server listening on port ${PORT}`);
});
```
这个示例使用了 Express.js 框架和 body-parser 中间件,用于处理 POST 请求的请求体。注册页面是一个简单的 HTML 表单,具有三个输入字段:用户名、电子邮件和密码。当用户提交表单时,它将发出 POST 请求,该请求将被处理并将用户信息保存到数据库中。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)