2017-09-22 1 views
0

私はNode.jsの初心者ですが、まだチュートリアルに従っています。私はチュートリアルが私に示唆したのと全く同じことをしましたが、私はまだこのエラーがあります。これは私が次のすべての行とすべての次のコードにつづくエラーです。Node.jsコードの作成中にapp.sendがWebStormの関数エラーではありません

コードWebStormで書かれており、私はちょうどこの2つの行に変更:

const express = require('express'); 
const path = require('path'); 
const favicon = require('serve-favicon'); 
const logger = require('morgan'); 
const cookieParser = require('cookie-parser'); 
const bodyParser = require('body-parser'); 

const app = express(); 

// view engine setup 
app.set('views', path.join(__dirname, 'views')); 
app.set('view engine', 'jade'); 

// uncomment after placing your favicon in /public 
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico'))); 
app.use(logger('dev')); 
app.use(bodyParser.json()); 
app.use(bodyParser.urlencoded({ extended: false })); 
app.use(cookieParser()); 
app.use(express.static(path.join(__dirname, 'public'))); 

app.get('/', (req, res) => { 
    app.send('This is a Node Program.'); 
}); 

// catch 404 and forward to error handler 
app.use(function(req, res, next) { 
    let err = new Error('Not Found'); 
    err.status = 404; 
    next(err); 
}); 

// error handler 
app.use(function(err, req, res, next) { 
    // set locals, only providing error in development 
    res.locals.message = err.message; 
    res.locals.error = req.app.get('env') === 'development' ? err : {}; 

    // render the error page 
    res.status(err.status || 500); 
    res.render('error'); 
}); 

module.exports = app; 

エラー:

app.send is not a function 

TypeError: app.send is not a function 
    at C:\Users\Tuladhar\WebstormProjects\NodeDemo\app.js:23:8 
    at Layer.handle [as handle_request] (C:\Users\Tuladhar\WebstormProjects\NodeDemo\node_modules\express\lib\router\layer.js:95:5) 
    at next (C:\Users\Tuladhar\WebstormProjects\NodeDemo\node_modules\express\lib\router\route.js:137:13) 
    at Route.dispatch (C:\Users\Tuladhar\WebstormProjects\NodeDemo\node_modules\express\lib\router\route.js:112:3) 
    at Layer.handle [as handle_request] (C:\Users\Tuladhar\WebstormProjects\NodeDemo\node_modules\express\lib\router\layer.js:95:5) 
    at C:\Users\Tuladhar\WebstormProjects\NodeDemo\node_modules\express\lib\router\index.js:281:22 
    at Function.process_params (C:\Users\Tuladhar\WebstormProjects\NodeDemo\node_modules\express\lib\router\index.js:335:12) 
    at next (C:\Users\Tuladhar\WebstormProjects\NodeDemo\node_modules\express\lib\router\index.js:275:10) 
    at SendStream.error (C:\Users\Tuladhar\WebstormProjects\NodeDemo\node_modules\serve-static\index.js:121:7) 
    at emitOne (events.js:115:13) 

を誰かがこのエラーで私を助けることができますか?私はいくつかのライブラリファイルや何かを失っているかもしれません。このエラーを修正し、これらのエラーを防ぐために何をすべきか教えてください。

答えて

1

私はあなたがこのように "RES" オブジェクトに送信することがあると思う:

res.send('This is a Node Program.'); 

はそれがお役に立てば幸いです。

+0

ありがとうございます。出来た。 – DKTLDHR

関連する問題