azure node.js console.log not logging into stdout or stderr files - node.js

I have a node.js app in azure (app service). The node.js is using the following modules
"scripts": {
"start": "node bin\/www",
"test": "mocha"
},
"dependencies": {
"async": "^1.5.2",
"bluebird": "^3.3.4",
"express": "^4.13.3",
"ioredis": "^1.15.1",
"lodash": "^4.6.1",
"socket.io": "^1.4.5"
},
"devDependencies": {
"chai": "^3.5.0",
"socket.io-client": "^1.4.5"
}
I wanted to enable the logging of app so i set the environment variable DEBUG = * using the portal->configure->app settings. since then, the app's express and socketio logs started to appear in /LogFiles/Application folder with cryptic name xxxxxx-nnnn-stderr-nnnnnnnnnnnnnn.txt
I added a console.log statement in one of the files in my app's lib folder
function MessageActions(redis, io) {
...
}
MessageActions.prototype.routeMessage = function(message) {
console.log('routeMessage: ' + JSON.stringify(message)); //this is not appearing anywhere in logs
var self = this;
return Promise.join(
self.checkUserMessage(message),
self.checkGroupMessage(message),
function(sendtarget, sendgroup) {
if(!sendtarget && !sendgroup) {
var pmsg = util.inspect(message);
throw new Error('Failed to route message: ' + pmsg);
}
}
);
}
I am sure that this function is being called as i could see the below error in the stderr file
[Error: Failed to route message: { ... }]
But i am not able to find the log statement added with console.log anywhere in this stderr file. also, there is no stdout file in the /LogFiles/Application folder.
How to add a log statement and where to check for it?
My IISNode.yml file has the following two lines
loggingEnabled: true
devErrorsEnabled: true

Please try to set the Application Logging (Filesystem) to on to enable the streaming log feature.
After that, you will find several logs files in /LogFiles/Application folder with cryptic name xxxxxx-nnnn-stdout-nnnnnnnnnnnnnn.txt which contain the output of your console.log().
But please notice the description:
Enable application logging to collect diagnostic traces from your web app code. You'll need to turn this on to enable the streaming log feature. This setting turns itself off after 12 hours.
To keep a persistence logging files in Node.js applications, you can use some node.js logging libraries like winston.

There is a way to see the console output live if you take the following steps:
Open website blade in Azure portal
Click on the tools icon
Click on the "Visual Studio Online" tool
Toggle the tool to "On"
...wait while the extension is enabled
Click the "Go->" icon under the tool toggle.
Once Visual Studio Online "Monaco" window is up, you can "Run" your application which should show your website in another window, but your "Monaco" window will have the console output from your application.
Hope this helps find your problem.

In your Index.js/Messages , replace the following code:
if (useEmulator) {
var restify = require('restify');
var server = restify.createServer();
server.listen(3978, function() {
console.log('test bot endpoint at http://localhost:3978/api/messages');
});
server.post('/api/messages', connector.listen());
}
else {
module.exports = { default: connector.listen() }
}
with:
if (useEmulator) {
var restify = require('restify');
var server = restify.createServer();
server.listen(3978, function() {
console.log('test bot endpoint at http://localhost:3978/api/messages');
});
server.post('/api/messages', connector.listen());
}
else {
var listener = connector.listen();
var withLogging = function(context, req) {
console.log = context.log;
listener(context, req);
}
module.exports = { default: withLogging }
}
This will override the console.log function. Hope , this will help.

Related

{Action name} isn't responding right now. Try again soon

I'm new with the ActionSDK and I created an project with the Action SDK.
The fulfillment of my actions is deploy in Azure as a web service.
I've being updating my action with:
gactions update --action_package action.json --project "projectID"
this being said, the update is successful.
this is my action.json:
{
"actions": [
{
"name": "MAIN",
"intent": {
"name": "actions.intent.MAIN",
"trigger": {
"queryPatterns": [
"talk to Conduent Helper",
"Talk to conduent help"
]
}
},
"fulfillment": {
"conversationName": "conduentHelpTest"
}
}
],
"conversations": {
"conduentHelpApp": {
"name": "conduentHelpTest",
"url": "https://dialogflowappnc.azurewebsites.net",
"fulfillmentApiVersion": 2
}
}
}
this is a fulfillment code I found after trying my own and had no success with it:
'use strict';
var express = require('express');
var bodyParser = require('body-parser');
var exps = express();
const ApiAiApp = require('actions-on-google').ApiAiApp;
exps.use(bodyParser.json());
// API.AI actions
const WELCOME_ACTION = 'input.welcome';
exps.post('/', function(request, response) {
console.log("hello World");
const app = new ApiAiApp({request, response});
function greetUser (app) {
app.tell("Hello World!");
}
let actionMap = new Map();
actionMap.set(WELCOME_ACTION, greetUser);
app.handleRequest(actionMap);
});
exps.listen((process.env.PORT || 7001), function() {
console.log("App up and running, listening.")
})
Whenever I test in the simulator the response is:
{Action name} isn't responding right now. Try again soon.
Whenever I do an update with the command above I see in my web service a request. But when I try to test the action in the simulator I see no request being made.
If someone can point me in the right direction. Point out any knowledge I most gain before proceeding. I there's more info I need to provide let me know and thanks.
Sorry I do not have enough points to comment but We are currently experiencing an outage you can see here if you are being impacted https://azure.microsoft.com/en-us/status/
You will want to monitor the Azure Status Page for further updates. Unfortunately we cannot do anything until the problem has been mitigated by engineering.
There are a couple of potential issues:
First - you haven't shown your package.json file, but the code suggests you're using an older version of the actions-on-google library. So the code itself may not be running. Check your runtime logs to make sure it is.
Next, you've specified that it should be listening on port 7001, but the URL you've provided in the actions.json file doesn't include the port number. If that is the host and port it is running on, and you haven't provided a proxy of some sort, then you need to specify the URL as https://dialogflowappnc.azurewebsites.net:7001/
Also, if you're running on port 7001, you likely haven't opened up the firewall to access it.
But it seems likely you're running a proxy (or you should), since you also need to be providing a valid HTTPS connection with a valid SSL certificate. If this is a self-signed certificate, the connection may still be rejected.

node JS and Out of Range Error

I'm trying to build my first node js application, to manage some telegram account. I don't want to create a telegram bot, which is making it really hard since most example relating to node js and telegram is bot related. I seem to be running into a lot of roadblocks, this being one of them...
I am trying initialize a connection to telegram, but I am getting the following error
internal/buffer.js:35
throw new ERR_OUT_OF_RANGE('value', `>= ${min} and <= ${max}`, value);^
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must
>= 0 and <= 4294967295. Received -2083955988
and it seems to be happening on this line of code
const { MTProto } = require('telegram-mtproto')
this is what the init.js file looks like
console.log('start init')
const { MTProto } = require('telegram-mtproto')
console.log('const MTProto set')
const api = {
invokeWithLayer: 0xda9b0d0d,
layer: 57,
initConnection: 0x69796de9,
api_id: 12345,
app_version: '1.0.1',
lang_code: 'en'
}
console.log('init api set')
const server = { webogram: true, dev: true }
const telegram = MTProto({ api, server })
console.log('init complete')
module.exports = telegram
I have put in a number of console.logs to try and trace out exactly where the error occurs, the first log of 'start init' prints and then the error happens, If I remove or comment out the
const{MTProto}=require('telegram-mtproto')
line then it will print the second log of 'cont MTProto set'. I am not sure why I am getting this error or exactly what it means or how to fix / avoid it.
I am using visual Studio 2017 and have added the the telegram-mtproto package in the package.json file like this.
{
"name": "test-telegram-login",
"version": "0.0.0",
"description": "testTelegramLogin",
"main": "server.js",
"dependencies": {
"crypto-address": "0.0.2",
"telegram-api": "^4.1.0",
"telegram-mt-node": "^0.9.7",
"telegram-mtproto": "^1.0.5"
},
I assume you need to update your WebSocket version or downgrade your Node.js version
I advice update the websocket module, in package.json file.
For example:
Change
"websocket": "^1.0.24"
to
"websocket": "^1.0.28"
Btw don't forget that you will need to delete your node_modules folder and do
npm install
for downloading all modules once again.
Of course if you don't want to download all modules, you can delete only ../node_modules/websocket folder and install websocket module.
npm install websocket

Electron with node-notifier display windows 10 notification

I'm trying to make a simple app that should display notification when button is clicked. The problem is that the notification does not show, but console.logs are showing. Should the notification work on development mode? (meaning just running electron ., and I don't have to build and install the app)
Windows OS:
Edition: Windows 10 Home
Version: 1709
Build:16299.98
NOTE: Toast is enabled (banner, action center) under System->Notification & Actions
Code:
// main.js
const { app, BrowserWindow, ipcMain, Notification } = require("electron");
const path = require("path");
const url = require("url");
let win;
function createWindow() {
// Create the browser window.
win = new BrowserWindow({ width: 800, height: 600 });
// and load the index.html of the app.
win.loadURL(
url.format({
pathname: path.join(__dirname, "index.html"),
protocol: "file:",
slashes: true
})
);
// Open the DevTools.
// win.webContents.openDevTools()
// Emitted when the window is closed.
win.on("closed", () => {
// Dereference the window object, usually you would store windows
// in an array if your app supports multi windows, this is the time
// when you should delete the corresponding element.
win = null;
});
}
const appId = "elite-notifier";
app.setAppUserModelId(appId);
app.on("ready", createWindow);
console.log("notifying");
ipcMain.on("notify", () => {
console.log("notified");
const WindowsToaster = require("node-notifier").WindowsToaster;
const notifier = new WindowsToaster({
withFallback: false
});
notifier.notify(
{
title: "My awesome title",
message: "Hello from node, Mr. User!",
sound: true, // Only Notification Center or Windows Toasters
wait: false // Wait with callback, until user action is taken against notification
},
function(err, response) {
// Response is response from notification
console.log("responded...");
}
);
});
// index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Notifier!</h1>
<button type="button" id="notify">Click here to trigger a notification!</button>
<script type="text/javascript">
const { ipcRenderer } = require('electron');
const button = document.getElementById('notify');
console.log('BUTTON: ', button)
button.addEventListener('click', function(event) {
console.log('clicked...');
ipcRenderer.send('notify')
});
</script>
</body>
</html>
I've got it working now, thanks to all the people here :) https://github.com/mikaelbr/node-notifier/issues/144#issuecomment-319324058
Based on anthonyraymond's comment, you need to have your app INSTALLED in your windows machine with an appId. You can configure appId in your package.json like this.
{
"name": "myapp",
"version": "1.0.0",
"description": "test",
"main": "main.js",
"build": {
"appId": "com.myapp.id"
}
}
The appId does not need to have that java/android format, my app just have an appId of elite-notifier.
Then you can pass the appId when calling the notify function of notifier.
notifier.notify(
{
appName: "com.myapp.id", <-- yes, the key here is appName :)
title: "Hello",
message: "Hello world!",
wait: true
},
function(err, response) {
// Response is response from notification
console.log("responded...");
}
);
After installation, This will work even on development mode (by running electron . command) provided that you'll not change the appId of your app after installation since there will be a mismatch on the installed one and the development version of the app.
You don't need to use IPC and send notifications from the main process, this is supported from the renderer process using the HTML5 notification API.
let myNotification = new Notification('Title', {
body: 'Lorem Ipsum Dolor Sit Amet'
})
myNotification.onclick = () => {
console.log('Notification clicked')
}
I've also tried many things, but sometimes it works or not.
At last, I've found a way. This works well for not only "npm run dev", but also package built.
use Notification at renderer process.
register app id at package.json
"build": {
"appId": "my app id",
...
call app.setAppUserModelId("my app id") at main process (https://electronjs.org/docs/api/app#appsetappusermodelidid-windows)
Here app id can be any type of string.
This error doesn't need any configuration all you have to do is go to your setting and enable notification Because in some cases on your computer you just switched off notifications.
System Setting ->Notification & Actions
Then turn on Notification By clicking the switch (problem solved)
You can do this, it works for me even on windows 10.
in package.json
"build": {
"appId": "your.custom.app.id",
}
in main.js
app.setAppUserModelId("your.custom.app.id");

Forever module with node app executable file

I am working on Node JS application.
In this I have to check first user is connected with internet or not. If yes then check KinectRuntime-v2.0_1409-Setup installed or not.. and further more such kind of validations are there. so I have used the following code in my entry script:
What I have Done:
broadcast.js: // entry file which we use to start app
var tempkinect = require('./controllers/tempkinect.js');
tempkinect.controller(app);
require('dns').lookup('google.com',function(err) {
if (err){
server.listen(8000, function(req, res){
open('http://localhost:8000/internetnotfound'); // internet not found page.
return false;
});
}
else{
try{
var Kinect2 = require("kinect2");
var kinect = new Kinect2();
}
catch(ex) {
server.listen(8000, function(req, res){
open('http://localhost:8000/kinectnotfound');
open('https://www.microsoft.com/en-in/download/confirmation.aspx?id=44559');
return false;
}
} //else ends here
});
tempkinect.js file: // my controller file
module.exports.controller = function(app){
app.get('/kinectnotfound',function(req,res){
var errmsg = "KinectRuntime-v2.0_1409-Setup not installed on your computer. Download will start automatically, if not then";
var link = "https://www.microsoft.com/en-in/download/confirmation.aspx?id=44559";
var click = "Click Here!"
res.render('initialerror',{errormessage:errmsg, downloadlink : link, clickhere: click, title : 'Kinect Not Found'});
});
app.get('/internetnotfound', function(req,res){
require('dns').lookup('google.com',function(err) {
if (err){
res.render('initialerror',{errormessage:'Please Connect Internet for Login.',downloadlink : '', clickhere : '', title : 'Internet Not Connected'});
}
else{
res.redirect('/restart');
}
});
});
app.get('/restart', function (req, res, next) {
process.exit(1);
});
}
I am using enclose module which compiled the node js application and creates .exe file. Now, If I run application on my local machine using command prompt:
run > node broadcast.js
then in case of internet not found app displays corresponding page.( then I connect internet manually ) after connecting internet when I refresh the page it restarts the process, which is good as per required.
BUT, when I do the same using compiled application then it is giving me error:
What Error I am getting:
So can anyone please suggest what should be modified there?
Besides this, Forever should be installed as global on the system so it is working fine on my system but not on others with the compiled app.
Looks like you already have something running at port 8000 (possibly other copy of your app). I would make sure your app port is configurable either through environment variables or command line options. Likewise make sure it can be shut down gracefully to release the port.
As for forever, there is no reason to install it globally, package it with the application and then its available at ./node_modules/.bin

phonegap webos 3.0+

I have a phonegap iOS app that i ported to webos on the touchpad the app works great except for the one iOS plugin that i used. it basically saved the canvas data to the photo roll. From my understanding of webos i will need to create a node.js service and write the data to a buffer and finally to the file system, there is an example for that in the forums. however what i can not figure out is how to call all of this from my phonegap app. I believe i will need to have the following in my index.html file.
<script src="/opt/PalmSDK/Current/share/framework/enyo/1.0/framework/enyo.js" type="text/javascript"></script>
and something like
enyo.create({kind: "Main"}).renderInto(document.body);
my guess i will also have to have all of the "kind" data in a js file. but how do i do the little step from my app's js file to communicate with the service that is created. I looked in the phonegap 1.0.js file and see that they are calling services this way.
this.service = navigator.service.Request('palm://com.palm.applicationManager', {
method: 'launch',
parameters: {
id: 'com.palm.app.camera',
params: {
appId: 'com.palm.app.camera',
name: 'capture',
sublaunch: true,
filename: filename
}
},
onSuccess: successCallback,
onFailure: errorCallback
});
but i also noticed it appears that it is all mojo and what i am doing is enyo, so yes i am pretty confused the moment...
seems it should be easy to call a service in webos, say here is a string of image data and write it to the file system from my existing phonegap app. and not have to do everything in enyo. anyone have a sample of a webos plugin like this or know where to point me?
thanks tim
**Update
I have created a node service now as defined below, i think that works and i am trying to make the call to the service, but it does not get to it. the test app runs on my touchpad, but when i push the button to save the image i do not get into the service. I tried to follow what was done for the camera in the phonegap0.0.1.js file this is a copy of my service, how i defined it and how i am calling it. any ideas what i am doing wrong.
services.json =
"id": "com.tim.pgmojo1.service",
"description": "FileIO Service",
"services": [
{
"name": "com.tim.pgmojo1.service",
"description": "FileIO Service",
"commands": [
{
"name": "writefile",
"assistant": "WriteFileAssistant",
"public": true
}]
}]
}
** service code
var libraries = MojoLoader.require({ name: "foundations", version: "1.0" });
var fs = IMPORTS.require("fs");
var sys = require('sys');
var WriteFileAssistant = function() {}
WriteFileAssistant.prototype.run = function(future) {
var mypath = this.controller.args.thepath;
var mydata = this.controller.args.thedata;
console.log("in write file");
console.log("path=" + thepath);
console.log("image data=" + thedata);
var data = content.replace(/^data:image\/\w+;base64,/, "");
var buf = new Buffer(data, 'base64');
fs.writeFile('/media/internal/downloads/timimage.png', buf);
}
my call to the service**
this.service = navigator.service.Request('palm://com.tim.pgmojo.service', {
method: 'writefile',
parameters: {
thepath: '/media/internal/downloads/timimage.png',
thedata: canvasData
},
onSuccess: mySuccess,
onFailure: myFailure
});
currently i have this in my index.html file since it is only for testing..
Mojo is still included on the TouchPad. You can use the same service-calling functions as PhoneGap is doing.
In Enyo, access to on-device services is handled by the enyo.PalmService kind. You can see an example of an app that has a node.js service included and how calls are made to this service at https://github.com/palm/txjs-fortunecookie

Resources