Hello, everyone! I am starting a study in electron and in this application I am using angularJS, the detail is that I do not understand much about, and I can not think of a way to use the Node without the server being running, I would finally like to use the node modules in an Angular service . I'll try to get a better look at the sources:
I have my user.model.js:
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var UserSchema = new Schema({
name: String,
password: String
});
module.exports = mongoose.model('User', UserSchema);
In my userService.js:
(function () {
'use strict';
var express = require('express'),
mongoose = require('mongoose'),
User = require('./user.model.js')
angular.module('app')
.service('userService', ['$q', UserService]);
function UserService($q) {
return {
create: createUser
/*getUsers: getUsers,
getById: getUserById,
destroy: deleteUser,
update: updateUser*/
};
function createUser(user) {
var deferred = $q.defer();
User.create(user, function(err, res) {
if(err) { eferred.reject(err); }
deferred.resolve(res);
});
return deferred.promise;
}
}
})();
And in the controller of my view (userController.js)
(function () {
'use strict';
angular.module('app')
.controller('UsuarioController', ['userService', '$q', UsuarioController]);
function UsuarioController(userService, $q, $mdDialog) {
var self = this;
self.User = {};
self.saveUser = saveUser;
function saveUser($event) {
userService.create(self.User).then(function (res) {
console.log('Salvou' + res);
});
}
}
})();
If anyone knows how I can do this, I'll be very grateful!