Login with Node.js [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I want to do a POST action with node.js with a command line application.
The goal is to login to http://hbeta.net
(I want to create a application that post the username and the password automaticly)
thanks ;)

If the website supports posting data to the login and receiving a login cookie/token back, you can use the following code:
var cloudscraper = require('cloudscraper');
cloudscraper.post('http://hbeta.net/', {
username: 'username',
password: 'password'
}, function(error, response, body) {
if (error) {
console.log("an error has occured");
} else {
console.log(body, response);
}
});
This code will simply send a POST method to http://hbeta.net/ while bypassing their CloudFlare DDOS protection and send a username and password along with the request.

Related

How to send information from ejs to the server? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 days ago.
Improve this question
I am making a quiz website and I need the quiz.ejs to send the inputted values to the server. I want the quiz to display a sentence and the user to selected true or false (about 20 questions). I used JavaScript to change the displayed sentence and to store the answer. Is there away to send the stored answers to the server?
I know the "form" element exists, but since I use the same "true" and "false" check-boxes for all questions I can't just send the value. Do I have to make a new checkbox for each question or can I send the data from the JavaScript file.
Thank you so much in advance.
I don't know what to try.
You will need to do an ajax post, from the clientside
Either a standard html form post, or use a javascript library like axios, fetch or even jquery
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
You will need to receive the ajax post, from the server
This is handled in your node server.
const app = express()
// other stuff...
// Handle post to /user
app.post('/user', (req, res) => {
// handle request stuff here...
// return json etc optional.
// res.json({})
})

What are the exact steps for documenting an express API using swagger-jsdoc? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to document my express router endpoint using the swagger-jsdoc from NPM.
I've never user swagger and I want to know the exact steps to write it in my code and how eventually i'll be able to generate a YAML/JSON documentation file.
router.post('/docToSafe', (req, res, next) => {
let SafeProperties = req.body.SafeProperties;
let DocumentsArray = req.body.Documents;
if ((SafeProperties.PathToSafe) && (SafeProperties.ZipName) && (DocumentsArray[0].DocID)) {
res.writeHead(200, { 'content-type': 'text/plain' });
res.end();
}
else {
res.writeHead(500, { 'content-type': 'text/plain' });
res.end();
}
}

User is not define when I sent POST request to /api/users/login [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
How to sent post request to mLab Database to check if user have already account or not Server Response User is not Define. Check my code
// #route post api/user/login#
router.post('/login',(req,resp)=>{
const email=req.body.email;
const password=req.body.password;
// find user
user.findOne({email})
.then(user => {
if(!user){
return resp.status(404).json({email: "User not found "})
}
// check password
bcrypt.compare(password,user.password)
.then(isMatch=>{
if(isMatch){
resp.json({msg:'sucess'})
}else{
return resp.status(400).json({password:'password incorrect'});
}});
});
});
Post Request to Server
http://localhost:5000/api/users/login
Key Value
email MyEmail#gmail.com
Password MyPassword
Response from Server
ReferenceError: user is not defined
user.findOne({email}) should be User.findOne({email}). user with a capital U

how to track post request from node, if the data is received by requester or not [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I`m new at node
I use node as a back end server with mongodb
and call it using a android device
my case is I set timeout from android to post a request in node, then from android it just return timeout because it wait too long.. but after several seconds the data is created at mongodb because if internet is so slow so it takes several seconds, I just cut the connection in android and cant cut it at node.
anyone can help what is the best practice to using timeout in android? let say I set timeout to 60sec, if the request longer than 10 sec I want to cut the connection because it takes too long
thanks anyway :))
Try this
exports.testInsert = function(req, res){
testModel.update({user_id: req.body.user_id}, {$set: {username: 'test'}},{upsert: true, setDefaultsOnInsert: true})
.lean()
.exec(function(err, data){
if (err) {
res.send({ err_num: 100000, err_str: err });
return false
}
res.send({ err_num: 0, err_str: 'Success' })
})
}

RxJS + Node.js Http Request [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Nodejs server side implementation: How to use https://www.npmjs.com/package/request with https://www.npmjs.com/package/rx to make GET request to https://www.reddit.com/r/javascript.json?
Goal: I attempting to accomplish constant streaming whenever there are data changes to whatever site api url I'm using.
Unfortunately you will be unable to receive updates when https://www.reddit.com/r/javascript.json is updated as there is no way for them to push this information to the client.
Services such as Github will let you register a webhook which will let them push data to an endpoint on your server. I am unsure if Reddit supports this.
As an alternate solution, and building on what AkkarinZA said in his answer, you could poll the json document using something similar to the following:
var fetchContent = function(url) {
return rx.Observable.create(function (observer) {
request(url, function (error, response, body) {
if (error) { observer.onError(); }
else { observer.onNext({response: response, body: body }); }
observer.onCompleted();
})
});
};
rx.Observable.interval(1000)
.map(function() { return 'https://www.reddit.com/r/javascript.json' })
.flatMap(fetchContent)
.map(/* do something */)
.subscribe();
Polling such as this isn't a good approach.
You want to create an observable with observers notified from the callback. Try something like:
rx.Observable.create(function (observer) {
request('https://www.reddit.com/r/javascript.json', function (error, response, body) {
if (error) { observer.onError(); }
else { observer.onNext({response: response, body: body }); }
observer.onCompleted();
})
})
.map(/* do something */)
.subscribe();

Categories

Resources