I have a code where on error I return a status with an error message:
if (err){
res.render('page1', {status:2, msg:'Server Error : Probable unable to connect'});
return;
}
In my page1.ejs, I have coded the following way:
var status = <%= status %>;
alert ( 'The status = ' + status);
if( status == 2)
{
var msg = "'" + <%= msg %> + "'";
alert(msg);
}
OR
if( status == 2)
{
alert('"' + <%= msg %> + "'");
}
I am trying to get the value of status and msg - but since 'msg' exists as multiple words I am not able to find a way to capture complete strings as passed from NodeJS. Firebug shows error as:
SyntaxError: missing ) after argument list
alert('"' + Server Error : Probable unable to connect+ "'");
-------------------|
Try this:
alert('<%= msg %>');
I am not an expert for EJS, but maybe this could work var msg = <%= msg %>; alert(msg);? Or simply alert(<%= msg %>)?
Related
TypeError: this.keys.index is not a function
the console log show that the if condition line is error
app.get('/',(req,res)=>{
if(!req.session.authenticated){
res.redirect('/login');
}else{
res.redirect('/search')
}
})
it was fine until i start another server.js from a completely different folder. I have tried to reinstall the node_module to fix it but it just result the same. but the weird part is i can start the server in a vm without any problem. can any help me with this?
Cookies.prototype.get = function(name, opts) {
var sigName = name + ".sig"
, header, match, value, remote, data, index
, signed = opts && opts.signed !== undefined ? opts.signed : !!this.keys
header = this.request.headers["cookie"]
if (!header) return
match = header.match(getPattern(name))
if (!match) return
value = match[1]
if (!opts || !signed) return value
remote = this.get(sigName)
if (!remote) return
data = name + "=" + value
if (!this.keys) throw new Error('.keys required for signed cookies');
index = this.keys.index(data, remote)
if (index < 0) {
this.set(sigName, null, {path: "/", signed: false })
} else {
index && this.set(sigName, this.keys.sign(data), { signed: false })
return value
}
};
I realise that this answer is late in the day but might help someone with the same error. I was getting the error 'TypeError: this.keys.index is not a function' on line 73 of index.js in cookies when trying to use koa-session.
I eventually realised that I had set app.keys to a single value i.e.
app.keys = 'dieueyf7huienejnfef'
When it should be an array:
app.keys = ['dieueyf7huienejnfef']
I want to return an object using Enumerable of linqjs. But this code gives an error "Invalid or unexpected token". When I check the same condition using if condition in forEach then it is working perfectly. But what's problem with Enumerable?
Using Linqjs
var checkAddressForUpdate = Enumerable.From($scope.companyAddresslist).Where("$.Address === '" + $scope.ad_CompanyAddress.Address + "' && $.SlNo !== " + $scope.ad_CompanyAddress.SlNo).FirstOrDefault();
Using If Condition
var checkAddressForUpdate;
angular.forEach($scope.companyAddresslist, function (comAddress) {
if (comAddress.Address == $scope.ad_CompanyAddress.Address && comAddress.SlNo != $scope.ad_CompanyAddress.SlNo) {
checkAddressForUpdate = comAddress;
}
});
Error in console
enter image description here
Previously the code worked correctly. Why an internal error has occurred?
Is this a problem with the JavaScript API for Office?
https://learn.microsoft.com/en-us/outlook/add-ins/add-and-remove-attachments-to-an-item-in-a-compose-form
The link and title are correct. I checked it out.
var options = {
asyncContext: null
};
Office.context.mailbox.item.addFileAttachmentAsync(link, title, options, function (asyncResult) {
console.log("asyncResult: " + JSON.stringify(asyncResult));
if (asyncResult.status === "succeeded") {
$docName.prepend("<i class='ms-Icon ms-Icon--checkbox ms-font-m ms-fontColor-green'>");
$fileProcess.resolve();
} else {
console.log("Office.context.mailbox.item.addFileAttachmentAsync() [" + asyncResult.status + "] error: "//
+ JSON.stringify(asyncResult.error) + " value: " + JSON.stringify(asyncResult.value));
$fileProcess.reject();
$attachedDoc.addClass("ms-bgColor-error");
$docName.prepend("<i class='ms-Icon ms-Icon--alert ms-font-m ms-fontColor-error'></i>");
$docName.after("<div class='ms-ListItem-tertiaryText addedError'>" + asyncResult.error.message + "</div>");
}
});
I got an asyncResult:
asyncResult: {"value":null,"status":"failed","error":{"name":"Internal Error","message":"An internal error has occurred."}}
The problem was with a self-signed certificate.
I would like to enumerate the members object from the below structure.
I do not have prior experience in node.js, I have tried the following code and it doesn't seem to work.
exports.sendVaultUnlockedPush = functions.database.ref('/Vaults/{id}/action').onUpdate(event => {
let status = event.data.val();
if (status == 'lock') {
var db = admin.database();
var vaultRef = db.ref("/Vaults/" + event.params.id);
vaultRef.once('value').then(function(snapshot) {
var hasMembers = snapshot.child('members');
if (hasMembers) {
var memberRef = db.ref("Vaults/" + event.params.id + "/members");
memberRef.once('value').then(function(memberSnapshot) {
memberSnapshot.forEach(function(element) {
console(element.key + " - " + element.val());
}, this);
});
}
});
}
})
It throws the following error:
Error: Firebase.DataSnapshot.forEach failed: Was called with 2 arguments. Expects no more than 1.
at Error (native)
at z (/user_code/node_modules/firebase-admin/lib/database/database.js:42:1666)
at T.forEach (/user_code/node_modules/firebase-admin/lib/database/database.js:114:179)
at /user_code/index.js:34:36
at process._tickDomainCallback (internal/process/next_tick.js:135:7)
I would just like it to return the value of 'members' node. And I have no clue to do the same.
Any help is much appreciated in getting this sorted. Thanks!
According to the docs forEach takes only one parameter:
This should work:
var values;
memberSnapshot.forEach(function(element) {
console(element.key);
values = element.val();
for (var val in values) {
if (values.hasOwnProperty(val)) {
console(val, values[val]);
}
}
});
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
I am trying to put log files into a SFTP Server. When I try to run I get error Line 1 Char 28 Syntax error. Anyone have any Idea to different code they got working for VBS? Looking for something simple.
cscript Transfer.vbs /type:winscp /SourceFolder:PATH TO LOG DIR /FTPType:sftp /FTPSite: SFTPSITE:PORT /FTPUser:USER /FTPPass:PASS
<job>
<reference object="WinSCP.Session" />
<script language="JScript">
try
{
// Setup session options
var sessionOptions = WScript.CreateObject("WinSCP.SessionOptions");
sessionOptions.Protocol = Protocol_Sftp;
sessionOptions.HostName = "SFTP";
sessionOptions.UserName = "USER";
sessionOptions.Password = "PASS";
var session = WScript.CreateObject("WinSCP.Session");
try
{
// Connect
session.Open(sessionOptions);
// Upload files
var transferOptions = WScript.CreateObject("WinSCP.TransferOptions");
transferOptions.TransferMode = TransferMode_Binary;
var transferResult = session.PutFiles("c:\\Users\PATH TO LOGS\\*", "/", false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
for (var enumerator = new Enumerator(transferResult.Transfers); !enumerator.atEnd(); enumerator.moveNext())
{
WScript.Echo("Upload of " + enumerator.item().FileName + " succeeded");
}
}
finally
{
// Disconnect, clean up
session.Dispose();
}
}
catch (e)
{
WScript.Echo("Error: " + e.message);
WScript.Quit(1);
}
</script>
</job>`
So I just had to install the SDK for Windows machine. Register the .dll file that winscp gives you. Also register via Com as well. Thakn you for looking into it