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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -