var couchbase = require("couchbase");
var cluster = new couchbase.Cluster('127.0.0.1:8091');
var bucket = cluster.openBucket('LFC', function(err) {
if (err) {
throw err;
}
console.log('Success')
});
Here how i connect to the bucket but when i try to open the server it says : "Failed to connect to the bucket".
First of all change this line with:
var cluster = new couchbase.Cluster('couchbase://localhost:8091');
Then try to uninstall couchbase , erase everything and install again. If you haven't created the bucket 'LFC' first create it from console. Then run your code.
Related
I wanted to know whether "Node-redshift" module supports Copy From query, to get bulk data from S3 bucket and load it in Redshift?
If not what other options I can use to connect to Redshift and use Copy command.
node-redshift is just a basic javascript client, which will execute what ever query/statement/DML you provide it.
In order to execute a copy command, all you need is to initialize the client and execute the command:
var copyCommand = "copy DESTINATION_TABLE_NAME
from 's3://BUCKET_NAME/SOME_PREFIX/'
credentials
access_key_id 'AKIA...'
secret_access_key 'secret...';"
var Redshift = require('node-redshift');
var client = {
user: user,
database: database,
password: password,
port: port,
host: host,
};
var redshiftClient = new Redshift(client, [options]);
redshiftClient.connect(function(err){
if(err) throw err;
else{
redshiftClient.query(copyCommand, [options], function(err, data){
if(err) throw err;
else{
console.log(data);
redshiftClient.close();
}
});
}
});
There are several supported formats for the files stored in the bucket like CSV and PARQUET.
See copy command documentation: https://docs.aws.amazon.com/redshift/latest/dg/t_loading-tables-from-s3.html
Snippet was taken from the official redshift-node page https://www.npmjs.com/package/node-redshift, and adjusted for the question above.
There is also the official aws nodejs client https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Redshift.html, but the idea is the same.
I'm new to Electron and trying to make 1 st application in which I need to connect it to a SQL server database for data storing/retrieving. I've have installed this plugin (https://www.npmjs.com/package/mssql#connect-callback) and followed their instructions but got no success regarding the connection. The weird part is that I also get no error or whatever showing in the console so I'm totally lost. Any help would be much appreciated, thank you guys.
Ps: I'm sure that there's no problem with the database since I can still connect to it using the same config setting below with a database client manager tool.
Below is the code I've used for simple testing connection.
<script type="text/javascript">
$(document).ready(function () {
const electron = require('electron');
const sql = require('mssql');
const config = {
user: 'ql*****',
password: 'qlh****',
server: '123.20.****',
database: 'QLHS'
};
async () => {
try {
await sql.connect(config);
const result = await sql.query`select * from DM_DONVI`;
console.dir(result);
} catch (err) {
console.log(err);
}
};
});
</script>
The link you provided is working. I tried the same. The error log can be seen in view->Toogle Developer Tools. The issue is you need install mysql.
npm install mysql --save
Then the code works fine.
Thank you Mr :D Actually, the thing that didn't work in my original post is the async part. Changing that to this and everything is fine now:
sql.connect(config, function (err) {
if (err) console.log(err);
var request = new sql.Request();
request.query('select * from DM_DONVI', function (err, recordset) {
if (err) {
console.log("Something went wrong")
}
else {
var result = JSON.stringify(recordset);
console.log(recordset.recordsets[0]);
}
});
});
I'm creating a portal where users can select and upload single files from their PC to S3 on AWS.
Below is my server.js code:
app.post('/submit_doc', function(req, res){
var FileName = req.body.fileName,
Filedescription = req.body.filediscrip,
InputFileName = req.body.inputfile;
AWS.config.region = 'eu-west-1';
var fileStream = fs.createReadStream(FileName);
fileStream.on('error', function (err) {
if (err){
console.log("Error reading file: ", err);
res.send(500);
}
else{
fileStream.on('open', function () {
var s3 = new AWS.S3();
s3.putObject({
Bucket: 'exampleassetcare.com',
Key: 'reports/'+FileName,
Body: fileStream
}, function (err) {
if (err) {
console.log("Error uploading data: ", err);
res.send(500);
}
});
});
I get the error: No such file or directory.
Can someone please help?
If I'm understanding you correctly, this code you've posted is running on the server. But the inputs are provided by the client, yes? If so, your server would be trying to find a file locally, based on a file path that the client gave you... So the file won't exist...
If I was a malicious user and I told your server to upload a file path /etc/passwd, your server would go and expose the hashed passwords (assuming it was a Linux system, and assuming there were proper permissions, etc... But you get the idea).
change it to
var FileName = req.body.fileName,
Filedescription = req.body.filediscrip,
InputFileName = req.body.inputfile;
AWS.config.region = 'eu-west-1';
console.log(FileName)
var fileStream = fs.createReadStream(FileName);
and check that your file exists, looks like something wrong with path to file.
I am using node v.0.10.33 couchbase, node module v.2.0.0 and couchbase-server-v.3.0.1
var couchbase = require("couchbase");
// Connect to Couchbase Server
var cluster = new couchbase.Cluster('10.50.10.31:8091');
var bucket = cluster.openBucket('beer-sample', function(err) {
if (err) {
// Failed to make a connection to the Couchbase cluster.
throw err;
}
// Retrieve a document
bucket.get('aass_brewery-juleol', function(err, result) {
if (err) {
// Failed to retrieve key
throw err;
}
var doc = result.value;
console.log(doc.name + ', ABV: ' + doc.abv);
// Store a document
doc.comment = "Random beer from Norway";
bucket.replace('aass_brewery-juleol', doc, function(err, result) {
if (err) {
// Failed to replace key
throw err;
}
console.log(result);
// Success!
process.exit(0);
});
});
});
when i run the above program on the same machine in which couchbase server is installed its working fine..
with this line
var cluster = new couchbase.Cluster('127.0.0.1:8091');
But when i run with another system which connected through Local area network I am getting network error. with this line
var cluster = new couchbase.Cluster('10.50.10.31:8091');
this error...
Couchbase Error : Network Failure
also tried
var cluster = new couchbase.Cluster('couchbase://10.50.10.31')
not working...
var cluster = new couchbase.Cluster('couchbase://localhost')
working fine...
Where i am going wrong please help me...
sorry for mistakes.
As per Couchbase Node.js SDK documentation, try creating connection like this:
var couchbase = require("couchbase");
var bucket = new couchbase.Connection({
'bucket':'beer-sample',
'host':'10.50.10.31:8091'
}, function(err) {
if (err) {
// Failed to make a connection to the Couchbase cluster.
throw err;
}
// your code to work with bucket here...
});
The problem is with python and node-gyp
i have upgraded python
and rebuild the couchbase module
cd path_to_nodejs_project/node_modules/coucbase/
node-gyp clean
node-gyp configure
node-gyp build
This solved my problem
I am trying to run the simplest hello world with Node.js and the mssql package.
https://www.npmjs.org/package/mssql
I create a new folder, with an empty JS file (app.js)
I copy and paste the sample from the mssql package page to the js file.
I only change the config object with my DB connection settings.
I run npm install mssql which is successful.
I run node app.js
What happens is that the code doesn't get into the callback after creating a connection. So in the code below:
var connection = new sql.Connection(config, function(err) {
alert(1);
...
//more code...
});
I never get to the alert. No exceptions or errors either
I am probably missing something... Can you please help me spot it?
Update: I should mention that the DB is on Azure...
Try this on your server side it works fine on my end:
var sql = require("mssql");
var dbConfig = {
user:'sa',
password:'password1',
server:'serverName',
database:'DBName'
};
var connection = new sql.Connection(dbConfig, function (err) {
console.log(err);
var request = new sql.Request(connection);
request.query("Select 'Hello World' as var1", function (err, recordset, returnValue) {
if (!err ){
console.log(recordset) ;
}else{
console.log(err)
}
});
});
OK, after digging a bit in the docs for Tedious, I found out that if the DB is on Azure you must include options: {encrypt: true} in your configuration object.
Now everything is working as expected.