Computerlucaworld Computerlucaworld - 1 year ago 77
Node.js Question

Express router doesn't work

Why this router doesn't work? I executed the route but it doesn't return any response.
Someone can explain to me why this code doesn't work?

var mongo = require('mongodb').MongoClient;
var express = require('express');
var app = express();
app.get ('/',function(req,resp){
if(err) throw err;
var cursor = db.collection('link').find();

function(doc) {
var count = 0;
var result = '';
if(count ==0) count++; result = "<!doctype html><html><head>URLShortener Home page</head><body><h1>In this page you can see the urls have already been shortened using this service<ul>";
if(doc !==null && count >0)
result += "<li>old URL: " + doc.old+"</li>";
result += "</ul></body></html>";



Answer Source

try this

cursor.toArray(function(err, doc){ console.log(doc); })

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download