Page not returning results

Benoit Jansen

i have node js + express 4 issues. i'm trying to call a function in index.js from login.js and get an answer printed out, but it doesn't even give me an error cause. console log gives me what i want in the console , but it doesn't render on the page.

index.js:

var express = require('express');
var router = express.Router();
var login = require('./login.js');

/* GET home page. */
router.get('/', function(req, res) {
res.render('index', { title: 'Express' });
});

/* Check login status */
router.get('/login', function(req, res) {
var response = login.logintest();
res.send(response);

});

module.exports = router;

login.js:

/* LOAD all requires needed here */
var request = require('request');
    request = request.defaults({jar: true});
var cheerio = require('cheerio');
/*
 * GET logincheck check if user needs to login
 */

exports.logintest = logintest;

function logintest(req, res)
      {
      request.get('http://internalbusinessdomain.com/', getStatus);
      };
function getStatus(err, mess, body)
      {
        if (!err && mess.statusCode == 200)
        {
            // console.log(body) ;
          var $Cheers=cheerio.load(body);
          // console.log($Cheers('li').text());
          if ($Cheers('li').text().substring(0,8) == "Inloggen"){
            console.log("htli")
            return "hastologin";

          }
          else {console.log("verbonden");
            return "connected";
          };
        }
        else
        { console.log("niet verbonden met tln");
          return "notconnected";
        };
      };
kaxi1993

you must use callback instead of returns your code looks like this

var express = require('express');
var router = express.Router();
var login = require('./login.js');

/* GET home page. */
router.get('/', function(req, res) {
res.render('index', { title: 'Express' });
});

/* Check login status */
router.get('/login', login.logintest);

module.exports = router;

login.js

var request = require('request');
    request = request.defaults({jar: true});
var cheerio = require('cheerio');
/*
 * GET logincheck check if user needs to login
 */

exports.logintest = logintest;

function logintest(req, res){
    request.get('http://internalbusinessdomain.com/',function (err, mess, body){
        if (!err && mess.statusCode == 200){
            // console.log(body) ;
            var $Cheers=cheerio.load(body);
            // console.log($Cheers('li').text());
            if ($Cheers('li').text().substring(0,8) == "Inloggen"){
                console.log("htli")
                res.send("hastologin");
            }else {
                console.log("verbonden");
                res.send("connected");
            };
        }else{
            console.log("niet verbonden met tln");
            res.send("notconnected");
        };  
    });
}

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Why is Scrapy returning duplicate results?

분류에서Dev

MySQL Full Text Search Returning 0 Results

분류에서Dev

Creating UTC time in momentjs is returning weird results

분류에서Dev

mysqli queries not returning results inside function

분류에서Dev

scraper only returning results for first 2 inputs

분류에서Dev

ElasticSearch Ruby returning results without ElasticSearch running

분류에서Dev

nslookup returning fake results for one particular domain

분류에서Dev

Internet category not returning any results in Synapse

분류에서Dev

Laravel - Calculations returning unexpected results with decimal/numeric data type (Postgres)

분류에서Dev

MySQL Random Select Query with limit returning different number of results (undesired)

분류에서Dev

Prepared statement is returning empty results, possible syntax error

분류에서Dev

SQL - Searching in a table based on information in another table and returning multiple results

분류에서Dev

mean of non zero elements - why are these two attempt returning different results?

분류에서Dev

Skype returning empty CHATMESSAGES results through the DBus API

분류에서Dev

NEST elasticsearch.NET search query not returning results (part 2)

분류에서Dev

filter function ng-repeat returning true but 0 results are displayed

분류에서Dev

Simple Search with Rails - Search Results on Separate Page

분류에서Dev

Show MySQL Results in a table without reloading page

분류에서Dev

Chrome - Turn off bell for find in page no results?

분류에서Dev

Add controls to this.Controls.Add( results controls at the beginning of my page

분류에서Dev

CodeIgniter: Pagination displaying links but not showing certain results per page

분류에서Dev

PHP Form Get and Post Output with If statement to output results on same page

분류에서Dev

Google Un-index / remove page from search results

분류에서Dev

After adding Spring Security to Spring MVC project, home page keeps returning 404 error

분류에서Dev

How can I use Selenium (Python) to do a Google Search and then open the results of the first page in new tabs?

분류에서Dev

ASP.NET MVC Search Results Page MapRoute Doesn't Work

분류에서Dev

My </form> tag disappears when I load the page in a browser, this results in my form not working, any ideas why?

분류에서Dev

I am using DataTables.net with MVC 5 and returning JsonResult. Page is showing table structure but not loading any data.Please have a look at my code

분류에서Dev

Excluding results

Related 관련 기사

  1. 1

    Why is Scrapy returning duplicate results?

  2. 2

    MySQL Full Text Search Returning 0 Results

  3. 3

    Creating UTC time in momentjs is returning weird results

  4. 4

    mysqli queries not returning results inside function

  5. 5

    scraper only returning results for first 2 inputs

  6. 6

    ElasticSearch Ruby returning results without ElasticSearch running

  7. 7

    nslookup returning fake results for one particular domain

  8. 8

    Internet category not returning any results in Synapse

  9. 9

    Laravel - Calculations returning unexpected results with decimal/numeric data type (Postgres)

  10. 10

    MySQL Random Select Query with limit returning different number of results (undesired)

  11. 11

    Prepared statement is returning empty results, possible syntax error

  12. 12

    SQL - Searching in a table based on information in another table and returning multiple results

  13. 13

    mean of non zero elements - why are these two attempt returning different results?

  14. 14

    Skype returning empty CHATMESSAGES results through the DBus API

  15. 15

    NEST elasticsearch.NET search query not returning results (part 2)

  16. 16

    filter function ng-repeat returning true but 0 results are displayed

  17. 17

    Simple Search with Rails - Search Results on Separate Page

  18. 18

    Show MySQL Results in a table without reloading page

  19. 19

    Chrome - Turn off bell for find in page no results?

  20. 20

    Add controls to this.Controls.Add( results controls at the beginning of my page

  21. 21

    CodeIgniter: Pagination displaying links but not showing certain results per page

  22. 22

    PHP Form Get and Post Output with If statement to output results on same page

  23. 23

    Google Un-index / remove page from search results

  24. 24

    After adding Spring Security to Spring MVC project, home page keeps returning 404 error

  25. 25

    How can I use Selenium (Python) to do a Google Search and then open the results of the first page in new tabs?

  26. 26

    ASP.NET MVC Search Results Page MapRoute Doesn't Work

  27. 27

    My </form> tag disappears when I load the page in a browser, this results in my form not working, any ideas why?

  28. 28

    I am using DataTables.net with MVC 5 and returning JsonResult. Page is showing table structure but not loading any data.Please have a look at my code

  29. 29

    Excluding results

뜨겁다태그

보관