i want to basic authentication using nodejs in documentation. it is written that use "localhost:8080". i am not understanding which url to use. in some other documentation, it is said it deprecated. to make request i am using axios npm package
some things that i tried but didn't work.
- axios.get("https://example.atlassian.net",{data:{username:"",password:""}}).then((result) => {})
please help me guys? i stucked in this problem from last 2 days. Thanks in advance
I think this will help you
Install with the node package manager npm:
$ npm install jira-client
// With ES5
var JiraApi = require('jira-client');
// With ES6
import JiraApi from 'jira-client';
// Initialize
var jira = new JiraApi({
protocol: 'https',
host: 'jira.somehost.com',
username: 'username',
password: 'password',
apiVersion: '2',
strictSSL: true
});
Example: Find the status of an issue
// ES5
// We are using an ES5 Polyfill for Promise support. Please note that if you don't explicitly
// apply a catch exceptions will get swallowed. Read up on ES6 Promises for further details.
jira.findIssue(issueNumber)
.then(function(issue) {
console.log('Status: ' + issue.fields.status.name);
})
.catch(function(err) {
console.error(err);
});
// ES6
jira.findIssue(issueNumber)
.then(issue => {
console.log(`Status: ${issue.fields.status.name}`);
})
.catch(err => {
console.error(err);
});
// ES7
async function logIssueName() {
try {
const issue = await jira.findIssue(issueNumber);
console.log(`Status: ${issue.fields.status.name}`);
} catch (err) {
console.error(err);
}
}
Documentation
documentation here
Related
Without the variables the server call works and gitlab is starting the pipeline.
But when I add variables to that call, it errors: "variables needs to be a map of key-valued strings".
This is my code:
axios
.post(`https://gitlab.myurl.com/api/v4/projects/${projectId}/trigger/pipeline`, {
ref: branch,
token: token,
variables: { STAGING_AREA: 'testing1', NOTIFY_STATUS: true, SLACK_USER_ID: 'xxxxx' }
})
.then(res => {
console.log('pipeline started:', res.data.web_url);
})
.catch(error => {
console.error('errorMessage', error);
});
What is the correct syntax for passing variables?
According to the docs, variable parameter should be in the form of variables[key]=value.
And the request is a multipart request so you need to use FormData.
Try running this code.
const pipelineTriggerBody = new FormData();
pipelineTriggerBody.append('ref', 'master'); // branch name
pipelineTriggerBody.append('token', 'CI_TOKEN');
pipelineTriggerBody.append('variables[STAGING_AREA]', 'testing1');
pipelineTriggerBody.append('variables[NOTIFY_STATUS]', true);
pipelineTriggerBody.append('variables[SLACK_USER_ID]', 'xxxxx');
axios
.post(
`https://gitlab.myurl.com/api/v4/projects/${projectId}/trigger/pipeline`,
pipelineTriggerBody
)
.then(res => {
console.log('pipeline started:', res.data.web_url);
})
.catch(error => {
console.error('errorMessage', error);
});
I was doing one thing wrong.
NOTIFY_STATUS: true
It seems that true can only be passed as a string:
NOTIFY_STATUS: 'true'
After this edit my code worked just fine.
I have compiled the C code using this command emcc add.c -o js_plumbing.js -s -s EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -s MODULARIZE=1
This is my Vue component code -
public instance:any = {
ready: new Promise(resolve => {
Module({
onRuntimeInitialized() {
this.instance = Object.assign(this, {
ready: Promise.resolve()
});
resolve();
}
});
})
};
public draw_outline() {
this.instance.ready
.then(_ => this.result_web = this.instance.addTwoNumbers(2,2));
}
draw_outline is getting called when I click on a text element.
And this is the error I'm getting -
So after this error I went to generate file and just added export to the module and this error disappears. but now my function in C "addTwoNumbers" is not getting called from instance.
if I print the value of instance I get
Does anyone know how to proceed from here?
I figured that when compiling I needed to use USE_ES6_IMPORT_META=0 flag so that WebAssembly module will use an older version of the import.meta.url line of code for systems that don't recognize the import style. so the command looks like emcc add.c -o js_plumbing.js -s EXTRA_EXPORTED_RUNTIME_METHODS=['ccall','cwrap'] -s ENVIRONMENT='web,worker' -s EXPORT_ES6=1 -s MODULARIZE=1 -s USE_ES6_IMPORT_META=0
This is my updated code -
Module().then(myModule => {
const result = myModule.ccall('addTwoNumbers',
'number',
['number', 'number'],
[4, 6]);
console.log("Value from wasm file", result);
});
My config file -
const path = require('path');
const contentBase = path.resolve(__dirname, '..', '..');
module.exports = {
configureWebpack: config => {
config.devServer = {
before(app) {
// use proper mime-type for wasm files
app.get('*.wasm', function (req, res, next) {
var options = {
root: contentBase,
dotfiles: 'deny',
headers: {
'Content-Type': 'application/wasm'
}
};
res.sendFile(req.url, options, function (err) {
if (err) {
next(err);
}
});
});
}
}
},
}
It is inside a function that I call on a click event . I can elaborate the whole process if someone is interested. It should not take this much time for anyone, I hope it helps others who have been looking for the solution. I realise I have not properly stated the problem in this post, I shall update everything here in a proper way soon.
AsyncStorage.getItem('token').then(value => {
token = value
console.log("Assigned token")
});
What is the proper way to read this synchronously?
I tried using await/async, they weren't installed, and have tried several ways to install babel generators.
How do I install async/await in React Native and read synchronously?
You don't need to install async/await. It's already there. To use, this is the way it should be. Declare the function as async then put await before AsyncStorage.
async Some(){
var token = await AsyncStorage.getItem('token')
console.log("Assigned token:",token)
});
}
Actually I think you are fine without await/async. You are just sending the "problem" of handling the promise to the parent function.
Usually, what I do, (if you are thinking about loading the auth token before continuing) is something like:
this.setState({loading: true}, () => {
AsyncStorage.getItem('token').then(value => {
token = value
console.log("Assigned token")
this.setState({loading: false}, () => {
this.continue();
})
});
})
I want to download file from other website to my pc using expressjs
I tried to use: res.download to download but it seems to be worked on my own server only
Here is my code:
res.download('http://apkleecher.com/download/dl.php?dl=com.instagram.android', 'folder', function(err){
if (err) {
console.log(err);
} else {
}
});
And it return the error:
{ Error: ENOENT: no such file or directory, stat '/home/keitaro/Desktop/google-play/http:/apkleecher.com/download/dl.php?dl=com.instagram.android'
errno: -2,
code: 'ENOENT',
syscall: 'stat',
path: '/home/keitaro/Desktop/google-play/http:/apkleecher.com/download/dl.php?dl=com.instagram.android',
expose: false,
statusCode: 404,
status: 404 }
In my guess, the problem is in the path of url.
Turning my comment into an answer since it worked for you...
You can fetch a resource from a remote web server using either http.get() or the request() module in node. If you like to use promises for your asynchronous operations, then the request-promise module is a promisified version of the request module and works great.
You can also use just plain http.get(), but it's a lot more work because you have to read the stream, rather the results yourself and install appropriate error handling, all of which the request() module does for you in one simple call.
Here's a simple example using the request-promise module:
const rp = require('request-promise');
rp('http://www.google.com').then(function (htmlString) {
// Process html...
}).catch(function (err) {
// process error here
});
res.download requires a path to your local filesystem.
try this:
res.redirect("http://apkleecher.com/download/dl.php?dl=com.instagram.android")
best way to download remote file is use stream .its use small mount of memory
**npm i got**
//========================
const got=require('got');
const fs=require('fs');
const path=require('path');
file_downloader(link,file_name){
var file_path = path.join(__dirname,file_name);
await got.stream(encodeURI(link))
.on('response', async (data) => {
//first response check headers like ['content-length']
})
.on('error', async (error) => {
console.log("===========Stream Error======= ");
console.log(error);
console.log("===========//End Stream Error======= ");
})
.on('downloadProgress', async (progress) => {
console.log(file.name, progress);
})
.pipe(fs.createWriteStream(file_path));
}
Anyone have experinace with seneca?
I have problem when I try to inclue mesh...
This is hapi route:
server.route({
method: 'GET',
path: '/api/ping',
handler: function (req, reply) {
server.seneca// load the mesh plugin
.use('mesh')
// send a message out into the network
// the network will know where to send format:hex messages
.act('foo:1,v:2', (err: any, out: any) => {
console.log(err)
// prints #FF0000
reply(null, out)
})
}
})
And this is my service:
require('seneca')({
})
//.use('zipkin-tracer', {sampling:1})
.use('entity')
.use('ping-logic')
.ready(function(){
console.log(this.id)
})
logic:
module.exports = function post(options) {
var seneca = this
seneca// provide an action for the format:hex pattern
.add( 'foo:1', function (msg, done) {
done( null, {x:1,v:100+msg.v} )
})
.use('mesh', { auto:true, pin:'foo:1' })
}
I get error
CL MISSING { foo: 1, v: 2 }
Anyone know what is porblem?
I have bumped into this, too. There were two things I had to do:
Use the master branch of seneca-mesh plugin. Unfortunately the published v0.10.0 on NPM is old (2017 March 7), and does not work with seneca v3.4.x
Add seneca.ready(function ()) in your hapi route like this:
server.route({
method: 'GET',
path: '/api/ping',
handler: function (req, reply) {
server.seneca// load the mesh plugin
.use('mesh')
.ready(function () {
// send a message out into the network
// the network will know where to send format:hex messages
this.act('foo:1,v:2', (err: any, out: any) => {
console.log(err)
// prints #FF0000
reply(null, out)
})
})
}
})
Also check this related github issue in which I asked the main contributor if there is a plan to have a new fixed version soon on NPM:
https://github.com/senecajs/seneca-mesh/issues/90
Hope this helps