npm open is not working while deploying it in server? - node.js

I have a nodejs code where at some point it uses a new tab for showing results.I got npm-open where it show my result in a new tab of the browser.But when i deploy it in a linux server, its neither opening a new tab nor throwing any error?
open( req.protocol + '://' + req.get('host')+"/view-document/?logos="+ logos+"&comp_name="+result_3[0].name +"&emp_name="+empname+"&start_date="+sdates+"&end_date="+edates+"&position="+designation+"&template=template1"+"&emp_id="+emp_id+"&issue_date="+issue_date+"&title="+title, function (err) {
if ( err ) {
res.redirect("/view-document/?logos=" + logos+"&comp_name="+result_3[0].name +"&emp_name="+empname+"&start_date="+sdates+"&end_date="+edates+"&position="+designation+"&template=template1"+"&emp_id="+emp_id+"&issue_date="+issue_date+"&title="+title);
return;
}
});

How could it?
The open command is a way to make your script interact with the OS it is running on, telling it to open a URL, image, etc. If you run your script on your local machine, this is fine and works as expected.
If you run your script on a server, there is no way it can communicate its request to your local machine. Think about it – should a random webpage/server have the ability to interact with the OS on client machines?
To make something like this work, you will need to split your script into two parts:
the parts that should reside on the server
the utility script which will communicate with the server and, when needed, run the open command

Related

Node Js--Child_process exec/execFile/Spawn is not opening exe/bat file after deployment from angular application

Here the requirement is to open the exe file from browser on button click.
This is the internal application, so client(angular) and server(node.js) is present in all machines, so here the idea is that, on button click I'm hitting node.js through socket.io and launching the exe by using node.js--child_process.
The above functionality is working fine, in my dev machine, on button click node-js is launching exe successfully, but after deployment (with dist files) it is not opening exe, and also there is no errors
This is my code
const { execFile } = require('node:child_process');
execFile('C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe', [], (error, stdout, stderr) => {console.log(error)});
Here my question is, Any config I need to change from node.js side to make it work with deployment files or is there any way to achieve this functionality in nodejs/angular?
Note:-
Even I tried to open .bat file by using spawn to trigger the exe, it is working fine in my dev-machine, but not working after deployment.
Thanks in Advance!

Meteor server side remote debugging

Versions
I'm using Meteor 1.0.3 and node 0.10.35 on a small Ubuntu Server 14.04 LTS (HVM), SSD Volume Type - ami-3d50120d EC2 instance.
Context
I know how to do server side debugging on my development box, just $ meteor debug and open another browser pointing to the url it produces -- works great.
But now, I'm getting a server error on my EC2 instance I'm not getting in development. So I'd like to set up a remote debug session sever side.
Also, I deployed to the EC2 instance using the Meteor-up package (mup).
EDIT
In an effort to provide more background (and context) around my issue I'm adding the following:
What I'm trying to do is, on my EC2 instance, create a new pdf in a location such as:
application-name/server/.files/user/user-name/pdf-file.pdf
On my OSX development box, the process works fine.
When I deploy to EC2, and try out this process, it doesn't work. The directory:
/user-name/
for the user is never created for some reason.
I'd like to debug in order to figure out why I can't create the directory.
The code to create the directory that works on my development box is like so:
server.js
Meteor.methods({
checkUserFileDir: function () {
var fs = Npm.require('fs');
var dir = process.env.PWD + '/server/.files/users/' + this.userId + '/';
try {
fs.mkdirSync(dir);
} catch (e) {
if (e.code != 'EEXIST') throw e;
}
}
});
I ssh'd into the EC2 instance to make sure the path
/server/.files/user/
exists, because this portion of the path is neccessary in order for the above code to work correctly. I checked the path after the code should have ran, and the
/user-name/
portion of the path is not being created.
Question
How can I debug remote server side code in a easy way on my EC2 instance, like I do on my local development box?
Kadira.io supports remote errors/exceptions tracking. It allows you to see the stacktrace on server side exceptions in the context of your meteor methods.
See https://kadira.io/error-tracking.html for more detail.
It seems in my case, since I'm using Meteor-up (mup), I can not debug per-say, but get access to the remote EC2 instance server console and errors by using command $ mup logs -f on my development box.
This effectively solves my issue with being blind on the server side remote instance.
It still falls short of actual debugging remotely, which speeds up the process of finding errors and performance bottlenecks, but it's all we have for now.
For someone who still searching:
#zodern added server-side debugging of meteor apps to great meteor-up tool:
https://github.com/zodern/meteor-up/pull/976
Do mup meteor debug in deployment dir and you will be almost set, just follow the text.

How do I check custom TURN server is working with easyRTC

I am working on an application for Audio/Video calls using easyrtc.
I have added turn server details in server.js file to configure the turn servers I want to use.
var myIceServers = [
{url: "stun:stun.anyfirewall.com:3478"},
{url: "turn:turn.anyfirewall.com:443", "username":"xxxxx", "credential":"xxxxx"},
{url: "turn:turn.anyfirewall.com:443?transport=tcp", "username":"xxxxx", "credential":"xxxxx"}
];
then set options for appIceServers using below line of code.
easyrtc.setOption("appIceServers", myIceServers);
and configured the listener as well.
easyrtc.on("getIceConfig", function(connectionObj, callback){
callback(null, myIceServers);
}
After this when I am running easyrtc simple audio-video demo, from local machine, in chrome using two tabs it works fine.
Now I have two questions:
How do I make sure that easyrtc is using custom supplied TURN server configuration ?
And from where I need to test the links for my application, which will make sure that easyrtc is using custom supplied TURN url for tcp ? (i.e. firewall check).
You can turn the "log level" to "3" in server.js to see more detail logs, and use chrome://werbrtc-internals to see the chrome webrtc logs . I just set up a TURN server yesterday and in my way , I modified the easyrtc_default_options to using my own TURN,I think your configuration will work if you test with two client in different network, the Turn server will give you a feedback.
"from local machine, in chrome using two tabs it works fine." this is not using you TURN server.

How to disable the debug remote port in node-webkit desktop app

I wan't to protect the code of my node-webkit desktop application packaged in an exe file.
The problem is not on the file directly but with the dedicated port for remote debugging.
Perhaps I haven't understood something but, on Windows, if I execute a "netstat -a -o" command, I see an open port associated to the application and if I open this port on my browser, I have a page with "Inspectable WebContents" and a link to the webkit application.
With this debug window, it's possible to access to all the sources of the app and I don't know how to disable this feature.
For now, I think there is no actual way to disable remote debugging in nw.js.
Even so, according to the wiki, remote debugging seems to only be executed through the command line switches. Therefore you can block the chromium command line switches (or only --remote-debugging-port) to prevent arbitrary remote debugging by user until nw.js supports disabling functionality of remote debugging.
For instance:
const gui = require('nw.gui');
const app = gui.App;
for (let element of app.fullArgv) {
// app.argv has only user's switches except for the chromium args
if (app.argv.indexOf(element) < 0) {
app.quit(1); // invalid args!
}
}
However, I am not quite sure the above code could protect your application code, because the nw.js is using Chromium internally. So that, the application code would be extracted in temporary folder on initialization. Whereas above solution isn't really protect your nw.js application. See more details: https://github.com/nwjs/nw.js/issues/269
Note: node-webkit has changed name to nw.js

Access denied upon doing a GetDirectories() but Dir in Powershell works

I have a problem I hope someone might help me with.
I've created a custom action page where I among other things will scan a directory on a remote server for a set of directories, and inside those directories I am searching for a set of files.
However, when I execute the code on the production server I get an Access denied exception.
If I use the same code on my testserver (accessing the same remote server) it works just fine.
If I use powershell or explorer on the production server I can access the remote directory and files with no problems.
I am using the same account in all scenarios (if I print out Page.User.Identity.Name and SPContext.Current.Web.CurrentUser.LoginName they are the same and equal to the account I use on the test server and the one I am logged on with on the production server when accessing the remote server from command line or explorer).
The code looks like this:
string user = SPContext.Current.Web.CurrentUser.LoginName.Remove(0,7);
string user_path = "\\\\srv\\share1\\subdir\\dir\\" + user;
// The line below will raise an exception on the production server.
foreach (string board_path in Directory.GetDirectories(user_path, "Board*")) {
foreach (string board_file in Directory.GetFiles(board_path, "Board*.xml")) {
.
.
}
}
I cant figure out why the code runs on the testserver but not on the production machine. I am using SharePoint 2010 Standard.
Thanks in advance for any kind of help I can get.
/Fredrik
The problem was solved by using SPSecurity.RunWithElevatedPrivileges()!
/Fredrik

Resources