Express后台开发遇到的问题

连接mysql数据库问题

  1. 授权相关
Client does not support authentication protocol requested by server;

解决方法在mysql中执行如下语句

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'

Express响应相关

Cannot set headers after they are sent to the client

将请求头发送到客户端后无法设置请求头
客户端发送一次请求的时候,服务器端给出了多次响应

冲突了
res.send({'list': data})
res.render('index', { title: 'Express' });

res.send()发送http响应
渲染内容用res.render(),将会根据views的模板文件进行渲染。

不能两者都做,但你可以渲染页面,并在同一时间发送数据:

res.render('reports',{data:json}); 

效率:在页面上格式化展示数据
JSONVUE(chrome插件)
gildas-lormeau/JSONView-for-Chrome

你可能感兴趣的:(express,express,javascript,前端)