node.js - How to use model loopback in other process nodejs -


normally when run file server/server.js, boot loopback app , can use models loopback.

now have other program nodejs (not loopback), need access database. how can include models of loopback manipulate data ( insert, update, delete, select) in file nodejs ?

thank you

you can initialize , use loopback models , other functionalities without starting loopback app server. sample code

var loopback = require('loopback'); app = module.exports = loopback();  //create datasource app.datasource("mongo", {     "host": "localhost",     "port": 27017,     "connector": "mongodb" });  //create model json defination var model = loopback.createmodel({ ... });  //attach model datasource , app app.model(model, { datasource: "mongo" }); 

once models attached app, can start using them usual through app.model.modelname. have used create npm script project.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -