I succeed to generate all my models from my database. Then, I run the api by executing, 'node .'
I'm able to see all my web services but when I try to try out a service, there is an 500 error saying to me that There is no ACL table.
So, I open model-config.json and I saw that there were 4 models I didn't created before (User, AccessToken, ACL, RoleMapping and Role).
I would like to know if all these models has to exist in my database. And Do you know which properties I have to put in each table?
Thanks you in advance.
Error:
{
"error": {
"name": "Error",
"status": 500,
"message": "ER_NO_SUCH_TABLE: Table 'sed.ACL' doesn't exist",
"code": "ER_NO_SUCH_TABLE",
"errno": 1146,
"sqlState": "42S02",
"index": 0,
"stack": "Error: ER_NO_SUCH_TABLE: Table 'sed.ACL' doesn't exist\n [...]"
}
}
You will need to automigrate these tables yourself. See:
https://groups.google.com/forum/#!searchin/loopbackjs/automigrate$20default$20tables/loopbackjs/IiapgVVf-NQ/32yeCnNxBmIJ
https://github.com/strongloop/loopback/issues/591.
You need to migrate them yourself
Follow the basic procedure in Attaching models to data sources to change from the in-memory data source to the database you want to use.
Create server/create-lb-tables.js file with the following:
var server = require('./server');
var ds = server.dataSources.db;
var lbTables = ['User', 'AccessToken', 'ACL', 'RoleMapping', 'Role'];
ds.automigrate(lbTables, function(er) {
if (er) throw er;
console.log('Loopback tables [' - lbTables - '] created in ', ds.adapter.name);
ds.disconnect();
});
Run the script manually:
$ cd server
$ node create-lb-tables.js
For further details see loopback Documentation
var server = require('./server');
var ds = server.dataSources.db;
var lbTables = ['User', 'AccessToken', 'ACL', 'RoleMapping', 'Role'];
ds.automigrate(lbTables, function(er) {
if (er) throw er;
console.log('Loopback tables [' - lbTables - '] created in ', ds.adapter.name);
ds.disconnect();
});
Here
var ds = server.dataSources.db;
db would be your database name, which you are using in datasource.json .
database connection string:
{
"db": {
"name": "db",
"connector": "memory"
},
"inventory": {
"host": "localhost",
"port": 3306,
"url": "",
"database": "inventory",
"password": "root",
"name": "inventory",
"user": "root",
"connector": "mysql"
}
}
Here is my db name:
"database": "inventory"
Upadated code is
var server = require('./server');
var ds = server.dataSources.inventory;
var lbTables = ['User', 'AccessToken', 'ACL', 'RoleMapping', 'Role'];
ds.automigrate(lbTables, function(er) {
if (er) throw er;
console.log('Loopback tables [' - lbTables - '] created in ', ds.adapter.name);
ds.disconnect();
});
shoot this code with independent saved file in directory with node filename.js
And it works.
Related
i am trying to connect mssql database but i couldnt achieve that.
When i connect mssql on Microsoft SQL Server Management Studio 18;
https://i.stack.imgur.com/6xdI0.png -- Because of Windows Authentication, i have no password. And there is a username field passive as default, also node js doesnt accept default user name. Why? and what i am doing wrong? When i try to execute js file; https://i.stack.imgur.com/Ty0zA.png -- gives an user name error in cmd db.js file;
var sql = require('mssql');
// config for your database
var config = {
user: 'DESKTOP-S9H932R\\CUNEYT',
password: '',
server: 'localhost',
database: 'cuneyt'
};
// connect to your database
sql.connect(config, function (err) {
if (err) console.log(err);
// create Request object
var request = new sql.Request();
// query to the database and get the records
request.query('select * from borsa', function (err, recordset) {
if (err) console.log(err)
// send records as a response
res.send(recordset);
});
});
package.json file;
{
"name": "mssql_test",
"version": "1.0.0",
"description": "",
"main": "db.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"mssql": "^6.3.1"
}
}
OP solved but for anyone having trouble my issue was that I was connecting to a local DB within a domain. I had to add the option to my config object to be like
config:{
user:'xxxx',
password:'xxxx',
server:'servername',
database:'yourdb'
domain:'yourdomainname'}
In node.js I am getting error while running index.js file:
var dbConfig = {
user: "test",
password: "***",
server: "localhost",
database: "hello",
port: parseInt("3306"),
options: {
"enableArithAbort": true
}
};
app.get("/CodList", function(_req ,_res){
var Sqlquery = "select * from CodeList";
QueryToExecuteInDatabase(_res, Sqlquery);
});
How to fetch the records from dtabase using node.js?
I found this way to solve this problem :
options: {
encrypt:false
}
full :
const msSqlConfig={
server:SQL_SERVER_NAME,
port:SQL_PORT,
user:${SQL_USER_NAME},
password:${SQL_PASSWORD},
database:SQL_DB_NAME,
options: {
encrypt:false
}
}
Let's say I have a list of hostnames and ports, not all of which are HTTP related.
var config = {
"checks": [
{
"name": "NPM",
"hostname": "npmjs.com",
"port": 80
},
{
"name": "AWS",
"hostname": "aws.amazon.com",
"port": 443
},
{
"name": "RabbitMQ",
"hostname": "merry-butterfly.rmq.cloudamqp.com",
"port": 5671
}
]
}
What is an effective way to test that each of these services can be reached? My first thoughts were to use a typical telnet-like approach, I did this:
var telnet = require('telnet-client')
config.checks.forEach(function(check) {
var connection = new telnet()
var params = {
host: check.hostname,
port: check.port,
negotiationMandatory: false
}
connection.on('connect', function() {
connection.send('GET /', {
ors: '\r\n',
waitfor: '\n'
}, function(err, data) {
console.log(err, data);
connection.end()
})
})
connection.connect(params)
results.push(result);
});
The above seems to work, but I'm actually not sure what data to send to each individual services to get back a response that suggests the service is "reachable", I don't need to auth or do any operations with the service, just check that it can be reached. Additionally it raises an exception if the DNS is unreachable:
Error: getaddrinfo ENOTFOUND merry-butterfly.rmq.cloudamqp.com/api merry-butterfly.rmq.cloudamqp.com/api:443
What would be the appropriate way to handle the errors, and async test each of the entries in the list of "checks"?
Ping the host.
https://www.npmjs.com/package/ping
For example:
var ping = require('ping');
var hosts = ['192.168.1.1', 'google.com', 'yahoo.com'];
hosts.forEach(function(host){
ping.sys.probe(host, function(isAlive){
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
console.log(msg);
});
});
I have an Django project using Celery with RabbitMQ broker. And now I want to call django (celery) task from NodeJS server.
In my NodeJS I'm using amqplib. Which is allow me to send tasks to RabbitMQ:
amqp.connect('amqp://localhost', function(err, conn) {
conn.createChannel(function(err, ch) {
var q = 'celery';
ch.assertQueue(q, {durable: true});
ch.sendToQueue(q, new Buffer('What should I write here?'));
});
});
My question is what format celery use? What should I write to Buffer to call celery worker?
For example, in my CELERY_ROUTES (django settings) I have blabla.tasks.add:
CELERY_ROUTES = {
...
'blabla.tasks.add': 'high-priority',
}
how to call this blabla.tasks.add function?
I've tried many ways but celery worker giving me error: Received and deleted unknown message. Wrong destination?!?
I found solution http://docs.celeryproject.org/en/latest/internals/protocol.html here.
Example message format is:
{
"id": "4cc7438e-afd4-4f8f-a2f3-f46567e7ca77",
"task": "celery.task.PingTask",
"args": [],
"kwargs": {},
"retries": 0,
"eta": "2009-11-17T12:30:56.527191"
}
So code should be:
amqp.connect('amqp://localhost', function(err, conn) {
conn.createChannel(function(err, ch) {
var q = 'celery';
ch.assertQueue(q, {durable: true});
ch.sendToQueue(q, new Buffer('{"id": "this-is-soo-unique-id", "task": "blabla.tasks.add", "args": [1, 2], "kwargs": {}, "retries": 0}'), {
contentType: 'application/json',
contentEncoding: 'utf-8',
});
});
});
In my node application i am connecting to a postgres sql in remote system
I have the following connection code:
var sequelize = new Sequelize('postgres://username:password#xxx.xxx.xx.xx:5432/dbname');
Its working fine.. but the following connection is not working:
// initialize database connection
var sequelize = new Sequelize(
config.dbname,
config.username,
config.password, {
dialect: 'postgres',
port:'5432'------------------->specified port here..
});
My config file:
{
"server": {
"port": 3000,
"forks": 1,
"siteUrl": "http://xxx.xxx.xx.xxx:3000"
},
"dbpostgres": {
"host": "xxx.xx.xx.xx",
"username": "username",
"port" : 5432,
"password": "password",
"dbname": "dbname"
}
I am receiving the following error:
"Error: connect ECONNREFUSED"," at errnoException (net.js:770:11)","
Please help me to solve this..Thanks in advance.....
}