我编写了一个简单的代码并将其保存在try.js文件中.
var http = require('http');
var makeRequest = function(message) {
var options = {
host: 'localhost', port: 8080, path: '/', method: 'POST'
}
var request = http.request(options, function(response){
response.on('data', function(data){
console.log(data);
});
});
request.write(message);
request.end();
}
makeRequest("Here's looking at you, kid.");
Run Code Online (Sandbox Code Playgroud)
当我通过终端运行它时会出错
throw er; // Unhandled 'error' event,
Error: connect ECONNREFUSED
at errnoException (net.js:884:11)
at Object.afterConnect [as oncomplete] (net.js:875:19)error' event
Run Code Online (Sandbox Code Playgroud) 我已经使用npm intall mysql安装了mysql我正在测试以下代码并且它给出了一个错误
TypeError:Object #<Object> has no method 'createClient'
var mysql = require('mysql');
var client = mysql.createClient({
user: 'user',
password: 'abc'
});
client.query('USE databasenm');
Run Code Online (Sandbox Code Playgroud)
请帮我纠正代码
我想根据数据创建文件。如果文件存在今天的日期,那么它一定不能创建文件。我已经写了一些代码
path.exists('./LOG/BAlDate-Info' +Date()+'.txt', function(exists) {
if (!exists) {
fs.writeFile('./LOG/BALDate-Info' +Date()+'.txt',"BAl-Employee is called @ "+ Date(),function(err){
if(err){
console.log("error is: " + err)
}
else
console.log("no error found");
});
}
});
Run Code Online (Sandbox Code Playgroud)
在这种情况下,每次我运行此代码时,它都会创建文件,但我只想创建今天的单个文件。在这种情况下请帮帮我