2016-05-21 14 views
7

मैं स्थापित किया है 'व्यक्त' NPM का उपयोग कर, मैं सफलतापूर्वक, पोर्ट संख्या 3000 पर लेकिन थोड़ी देर मैं निम्न त्रुटि मिल गया के बाद सुनने मिल गया है"TypeError: res.sendStatus एक फ़ंक्शन नहीं है" मुझे कुछ देर बाद यह त्रुटि क्यों मिल रही है?

TypeError: res.sendStatus is not a function

हम जानते हैं, res.sendStatus(404) express.but से संबंधित है एक्सप्रेस स्पष्ट रूप से स्थित है।

यहाँ

var express = require('express'), 
app = express(); 

app.get('/', function(req, res){ 
    res.send('Hello Worlds'); 
}); 

app.use(function(req, res){ 
    res.sendStatus(404); 
}); 

var server = app.listen(3000, function() { 
    var port = server.address().port; 
console.log('Express server listening on port %s', port); 
}); 

यहाँ मेरा पूरा cmd उत्पादन होता है app.js में स्रोत कोड है,

> $ node app.js 
Express server listening on port 3000 
TypeError: res.sendStatus is not a function 
    at Object.handle (I:\mongoUniversity\hello_world_templates\app.js:14:9) 
    at next (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:174:15) 
    at pass (I:\mongoUniversity\hello_world_templates\node_modules\express\lib\router\index.js:110:24) 
    at Router._dispatch (I:\mongoUniversity\hello_world_templates\node_modules\express\lib\router\index.js:173:5) 
    at Object.router (I:\mongoUniversity\hello_world_templates\node_modules\express\lib\router\index.js:33:10) 
    at next (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:174:15) 
    at Object.expressInit [as handle] (I:\mongoUniversity\hello_world_templates\node_modules\express\lib\middleware.js:30:5) 
    at next (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:174:15) 
    at Object.query [as handle] (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\middleware\query.js:43:5) 
    at next (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:174:15) 
    at Function.app.handle (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\proto.js:182:3) 
    at Server.app (I:\mongoUniversity\hello_world_templates\node_modules\connect\lib\connect.js:67:37) 
    at emitTwo (events.js:87:13) 
    at Server.emit (events.js:172:7) 
    at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:525:12) 
    at HTTPParser.parserOnHeadersComplete (_http_common.js:88:23) 

मैं इसी तरह के सवाल, जहां वे जांच करने के लिए कहा कि अगर 'व्यक्त' स्थापित किया गया था जाँच कर ली है या नहीं, लेकिन मैंने इसे सही तरीके से स्थापित किया है। तो मैं गलत क्या कर रहा हूँ?

+1

आपके द्वारा उपयोग किए जा रहे एक्सप्रेस के संस्करण की जांच करें। केवल '4.x' 'res.sendStatus' का उपयोग करता है। –

+0

तय हो गया !, धन्यवाद @ पैट्रिक रॉबर्ट्स मैंने पाया कि "package.json" फ़ाइल में परिभाषित एक्सप्रेस संस्करण 3.x (अब अपडेट किया गया) था, लेकिन मैंने वैश्विक रूप से एक्सप्रेस 4.13.4 संस्करण स्थापित किया, इसलिए जब मैंने कमांड पर एक्सप्रेस संस्करण की जांच की लाइन यह हमेशा 4.x संस्करण लौटा, तो मैं संस्करण के बारे में कम चिंतित था। –

+0

एक्सप्रेस को विश्व स्तर पर स्थापित नहीं किया जाना चाहिए, इसलिए ऐसा करने से बचने का प्रयास करें। –

उत्तर

संबंधित मुद्दे