diff --git a/index.js b/index.js index 2d7e6834fb6366b3120c7a37cc5f637bc4a33928..0378daef30dce824343a3807a8c9fa6701243c1a 100644 --- a/index.js +++ b/index.js @@ -1 +1,44 @@ -console.log("欢迎来到 InsCode"); \ No newline at end of file +console.log("欢迎来到 InsCode"); + +//需要安装express +//启动后app.js,再使用请求html的接口 +const express=require('express') + +//创建一个网站app,网站可以存放多个网页 +const app=express() + +//批量批量执行 +for(let i=0;i<100;i++){ + //创建网页:app.listen对应的端口网站:一个端口可以有多个网页:write是直接编辑网页 + app.get('/page'+i,(req,resp)=>{ + resp.setHeader('Content-Type', 'text/html;charset=UTF-8') //解决启动网站后网页显示中文乱码的问题 + //写网页内容:读取数据库输出数据 + //action = "http://localhost:5000/" //后端接收数据的端口 + //method = "POST" //method的post方法提交请求至后端,供后台接收:估计经过后端处理后,可以将数据发回至前端,可能是 + //多按行时,要注意标签空格,否则不是html标签,是字符串 + let myhtml= + `
+ + 账号: + 密码: + ' +
` + resp.write('

js创建网页成功:这是网页'+ i +'

') + resp.write(myhtml) + resp.end() + }) +} + + + +//启动网站服务器:使这些网页可以访问:这里的端口是访问网页的端口,并非后端接收数据的端口: +app.listen(8000,()=>{ + console.log("server is statr 服务启动") +}) + + + +//采用 POST 方法,浏览器将会按照下面两步来发送数据。首先,浏览器将与 action 属性中指定的表单处理服务器建立联系,一旦建立连接之后,浏览器就会按分段传输的方法将数据发送给服务器 \ No newline at end of file diff --git a/package.json b/package.json index 72caa1750a1c44c18460a496d258fbd3c51c673a..aefbfb594b3178e69031831f8d16da175f51fc0e 100644 --- a/package.json +++ b/package.json @@ -4,15 +4,15 @@ "description": "", "main": "index.js", "scripts": { - "dev": "node index.js", - "test": "echo \"Error: no test specified\" && exit 1" + "dev": "node index.js", + "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], "author": "", "license": "ISC", "dependencies": { - "@types/node": "^18.0.6", - "node-fetch": "^3.2.6" + "@types/node": "^18.0.6", + "express": "^4.18.2", + "node-fetch": "^3.2.6" } - } - \ No newline at end of file +}