我是node.js的新手,并试图学习它.
在这里,我试图访问nodejs中的mySQL数据库.
我有这个使用的安装模块,npm install mysql但我没有得到任何文件夹中的mysql node_modules文件夹.
但是从终端安装mysql模块时我没有收到任何错误.因为这个问题我无法在程序中使用mysql模块而且我收到错误
module.js:340
throw err;
^
Error: Cannot find module 'mysql'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/opt/lampp/htdocs/1nodeapp/mysql.js:4:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
Run Code Online (Sandbox Code Playgroud) 我正在尝试实现输入数字字段,这将允许正数或负数.
我使用了"/^0|[1-9]\d*$/"正则表达式来表示ng-pattern.但它不起作用.对于字符输入,它没有显示任何错误.我在这里粘贴了我的代码.
我不想根据需要创建此字段.我只想要数字验证(不允许使用章程).
我想在我的angularJS应用程序中设置JS异常日志记录模块,为此我使用$ exceptionHandler.
我使用以下代码来记录应用程序错误:
app.config(function($provide) {
$provide.decorator("$exceptionHandler", function($delegate) {
return function(exception, cause) {
$delegate(exception, cause);
// alert(exception.message);
console.log(JSON.stringify(exception.message += ' (caused by "' + cause + '")'));
};
});
});
Run Code Online (Sandbox Code Playgroud)
但在这里,我只收到消息,但我想要所有与异常相关的细节,如errorMsg,url,行号等.
如何使用上面的代码获取所有这些细节?
我是node.js的新手,并试图学习它.
我已经安装了node-mysql NPM模块.这里我列出了访问mysql的代码:
// Include http module,
var http = require('http'),
// And mysql module you've just installed.
mysql = require("mysql");
// Create the connection.
// Data is default to new mysql installation and should be changed according to your configuration.
var connection = mysql.createConnection({
user: "root",
password: "",
database: "astitvabmt",
host: '127.0.0.1',
port: '3306',
_socket: '/var/run/mysqld/mysqld.sock'
});
// Create the http server.
http.createServer(function (req, res) {
// Attach listener on end event.
// Query the database.
connection.query('SELECT * FROM …Run Code Online (Sandbox Code Playgroud) 我想在expressJS应用程序中单点开发错误处理.
我在expressJS配置中添加了以下代码:
app.use(app.router);
app.use(function (err, req, res, next) {
console.error('ExpressJS : error!!!');
});
Run Code Online (Sandbox Code Playgroud)
因此,在应用程序中发生的任何错误然后上面的函数应该执行,以便我可以自定义方式处理错误.
但是,上面的函数没有在javascript错误或以下代码上执行:
throw new Error('something broke!');
Run Code Online (Sandbox Code Playgroud)
我看过:
http://expressjs.com/guide/error-handling.html和
http://derickbailey.com/2014/09/06/proper-error-handling-in-expressjs-route-handlers/
但是,我仍然无法在expressJS应用程序中进行通用错误处理.
任何人都可以解释我将如何在单点处理任何应用程序错误?