node + mysql:
When writing the demo today, I found that the code reported an error typeerror: res.render Is not a function, but I tested myself when it is not suitable for MySQL to query data res.render The () method is available, but when MySQL data is not available res.render() will not go wrong. Direct code:
Problem code
var express = require('express');
var router = express.Router();
const mysqlCon = require('../modules/mysql');
router.get('/', function(req, res, next) {
mysqlCon.query("SELECT empno,ename,job FROM emp WHERE empno > 1008",function(err,res){
if(err){
return res.redirect('/');
}
console.log('======================res==========================');
var UserInfo = res;
// UserInfo = JSON.parse(JSON.stringify(UserInfo))
res.render('index', {
title: 'Home Page',
UserInfo
})
})
});
report errors
Solution:
var express = require('express');
var router = express.Router();
const mysqlCon = require('../modules/mysql');
router.get('/', function(req, res, next) {
mysqlCon.query("SELECT empno,ename,job FROM emp WHERE empno > 1008",function(err,result){
if(err){
return res.redirect('/');
}
console.log('======================res==========================');
var UserInfo = result;
// UserInfo = JSON.parse(JSON.stringify(UserInfo))
res.render('index', {
title: 'Home Page',
UserInfo
})
})
});
The return value of MySQL query, res, can be changed to other definitions. Because the previous code style habitually defines the return value as res, which conflicts with the corresponding res in the node project res.render is not a function。 It’s not a big pit, mainly because the code habit has not been transformed…
Read More:
- TypeError: db.collection is not a function
- [Solved] Vue Error: Failed to mount component: template or render function not defined
- Taro Use React Hooks Error: TypeError: Object(…) is not a function
- Syntax Error: TypeError: this.getOptions is not a function
- Webpack Error: Module build failed: TypeError: this.getOptions is not a function
- Webpack packaging error TypeError: this.getOptions is not a function at Object.lessLoader
- [Vue warn]: Error in render: TypeError: Cannot read property ‘xxxx’of undefined
- Vue error in render: “typeerror: cannot read property ‘length’ of undefined”
- [Solved] vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in render: “TypeError: Cannot read property ‘length‘
- [Solved] VUE Use Filters Error: [Vue warn]: Error in render: “TypeError: Cannot read property ‘toFixed’ of undefined”
- VUE: Property or method “deleteFun“ is not defined on the instance but referenced during render. [How to Fix]
- this.$el.querySelectorAll is not a function [How to Solve]
- React Hook “useState“ is called in function “xxx“ which is neither a React function component or
- [Solved] MongoDB Error: TypeError: Object of type ObjectId is not JSON serializable
- Solve the data transfer between vue irrelevant components error: this.$store.commit is not a function
- TypeError: ‘WebElement’ object is not iterable error
- [Solved] MindSpore Network custom reverse error: TypeError: The params of function ‘bprop’ of
- NPM install Error cb.apply is not a function
- [Solved] Vue Install less Error: this.getOptions is not a function
- [vite] Internal server error:options.devServer.transformWidthEsBuild is not a function…