Service not getting installed using node-windows - node-windows

I tried using node-windows to create a service > "daemon" folder was getting created but service was not getting installed. Following is the code :
var Service = require('node-windows').Service;
var svc = new Service({
name: 'MyService',
description: 'Trial service',
script:'app.js',
abortOnError:false
});
console.log("....", svc);
svc.on('install', function() {
console.log('installed');
return svc.start();
});
svc.on('error', function() {
return console.log('error');
});
svc.on('start',function(){
console.log(svc.name+' started!');
});
svc.on('alreadyinstalled', function() {
return console.log('alreadyinstalled');
});
svc.install();

Here is the script I use and it works.
var Service = require('node-windows').Service;
// Create a new service object
var svc = new Service({
name:'AM-API-MDD port 3050',
description: 'API Server for MDD db (port:3050)',
script: 'C:\\Sites\\AM-API-MDD\\dist\\main.js',
// execPath: 'C:\\Program Files\\nodejs14\\node.exe'
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
svc.install();

Related

How to use the postgres-adapter in Socket.io in node.js

My current setup is as such:
I have connected to my postgres database and i also have the websocket connected fine to the frontend.
But I am not sure how to use the postgres-adapter as its suggested in the documentation:
They say that you make a pool instead of a Client - thats fine for the db - then you say you use the io.adapter(createAdapter(pool));
The main functionality I want to get at is - when a change occurs on the postgresdb - then a notification gets send out just as I have currently - but then it should be connected inside the websocket for the websocket to send a message with the data to all connected clients. Has anyone implemented this?
client.connect(err => {
if (err) {
console.log("Error in connecting database: ", err);
} else {
console.log("Database connected");
client.on('notification', (msg) => {
console.log(msg.payload);
console.log(msg)
});
const query = client.query("LISTEN update_notification");
}
})
const webSocketSetup = (server) => {
var io = new Server(server, {
cors: {
origin: [
'http://localhost:3000',
]
}
});
io.on('connection', (socket) => {
console.log('a user connected');
socket.on('disconnect', () => {
console.log('user disconnected');
});
socket.on('my message', (msg) => {
"" I Want the postgres Notification to be setup here. ""
});
});
}

Service Worker doesn't get data from cache

Task: Offline first;
I have some pages (which end in ?ind${number}.html and these pages are not caching. I resolve this problem with passing a second argument onto caches.match(event.request.url))
let CACHE = 'network-or-cache-v1';
self.addEventListener('install', function(event){
let offlinePage = new Request('/index.html');
self.skipWaiting();
event.waitUntil(
caches
.open(CACHE)
.then((cache) => cache.addAll(arrayToCache))
);
});
self.addEventListener('fetch', function(event){
const url = new URL(event.request.url);
console.log(url);
caches.match(event.request.url, {ignoreSearch: true}).then(function(response) {
return response || fetch(event.request);
})
event.waitUntil(update(event.request));
});
You could try creating a new request object and then pass it in to caches.match like
const requestNew = new Request(event.request, {ignoreSearch: 'true' });
caches.match(requestNew).then(///)

VueResource Vue.http.get Response Status Code 0

im having this issue where i send a request to the API to retrieve all users, the login function is called(index.vue) when called it tries to go to api/users/all which in this case should return all the users in that collection.
using Postman the API returns the correct results and if i console.log the output in the routeUsers before i send the response back, it outputs all the correct data to the console
when it returns to index.vue, the response status code is 0.
ive had a look online and some things are mentioning about CORS Headers but i dont think thats applicable to me and other things about the response has been cancelled,
can anyone shed some light on this for me and help me try to fix it?!
API main.js
var app = express();
var users = require('./routes/routeUsers');
app.use('/users', users);
module.exports = app;
api/models/users.js
var db = require('../Utilities/db')
module.exports.all = function(cb) {
var collection = db.get().collection('users')
collection.find().toArray(function(err, docs) {
cb(err, docs)
})
}
api/routes/routeUsers.js
var express = require('express')
, router = express.Router()
var user = require('../models/users');
router.get('/all', function(req, res) {
user.all(function(err, users) {
res.send(users);
})
})
Index.vue
export default {
data: function () {
return {
username: '',
password: '',
users: []
}
},
methods: {
login: function() {
Vue.http.get('/api/users/all').then((response) => {
console.log("SUCCESS",response);
this.users = response.body;
console.log(users);
}, function (error) {
console.log("Error", error.status); // handle error
});
}
}
};
The issue was that the inputs were in a form tag. removed Form tag and worked fine.

AngularJS Testing using Jasmine-Karma

I have a factory service inside a folder,,,i have mentioned the path in karma.conf.js file correctly and added the angular-mocks before that..But
if i try to load a factory/service which is not available in that folder then Unknown provider error is thrown
If i include the correct factory service then am not getting any error
But if i try to call a method in that factory/service,then the mocked service object is undefined and am getting cannot read a function from undefined error message..
I couldn't figure out why...can any1 help me in this issue..
Spec.js
describe('dfgh', function () {
var mockService,httpBackend;
beforeEach(function () {
module('app');
});
beforeEach(function () {
inject(function ($httpBackend, _familyService_) {
mockService = _familyService_;
httpBackend = $httpBackend;
});
});
it('Factory Service Testing', function () {
/// Code here
});
});
FamilySvc.js
(function() {
'use strict';
angular.module('app')
.factory('familyService', familyService);
familyService.$inject = ['$rootScope', '$http', '$q', 'service2', 'service3'];
function familyService() {
var a="Some String";
return a;
}
}());
Karma.conf.js
files: [
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'app/*.js', --> Holds FamilySvc.js
'tests/*.*' -- >holds Spec.js
],

How do I get attributes of Custom Session using Ember Simple Auth

PROBLEM: I don't know how to get the current session in a controller.
I have a custom authenticator, custom session, and initializer defined like so:
CUSTOM AUTHENTICATOR in ../app/authenticators/custom.js
var CustomAuthenticator = Base.extend({
authenticate: function(credentials) {
return new Ember.RSVP.Promise(function (resolve, reject){
var loginPromise = Ember.$.post('/api/login', {'email':credentials.identification, 'password':credentials.password} );
loginPromise.then(function (data){
resolve({
token: data.user.api_key,
userData: data.user
});
}, function(error){
reject(error);
});
});
}
});
CUSTOM SESSION in ../app/sessions/custom.js
import Ember from 'ember';
import Session from 'simple-auth/session';
var CustomSession = Session.extend({
after:'simple-auth',
currentUser: function(){
return this.container.lookup('ember_simple_auth:session');
}.property('currentUser')
});
export default CustomSession;
INITIALIZER in ../app/initializers/authentication.js
import CustomAuthenticator from '../authenticators/custom';
import CustomSession from '../sessions/custom';
export default {
name: 'authentication',
before: 'simple-auth',
initialize: function(container) {
container.register('authenticator:custom', CustomAuthenticator);
container.register('session:custom', CustomSession);
}
};
I'm trying to get the token and userData in one of my controllers by using this.get('session') but it's giving me the following:
Class {store: Class, __ember1420041799205: "ember297", __nextSuper: undefined, __ember_meta__: Object, constructor: function…}
and I see the ember_simple_auth:session key and values in the local browser storage {"authenticator":"authenticator:custom","token":"123456789","userData":{"id":"1","email":"something#email.com","api_key":"123456789","expiry_time":"2014-12-31 14:02:56"}}
I basically need to get what's in the local storage. How do I do this?
Ah, I figured out the problem. When first authenticating, the session variable was there but refreshing the page got rid of the session's content because I did not have a restore function in my authenticator.
restore: function(data) {
return new Ember.RSVP.Promise(function (resolve, reject){
console.log('RESTORE');
if(!Ember.isEmpty(data.token)) {
console.log('Found token: ' + data.token);
resolve(data);
} else {
console.log('Token Not Found!');
reject();
}
});
}

Resources