2017-08-23 2 views
0

私はNODE JSアプリケーションにデバッグしています。ノードjには非常に新しいです。 I私は http://localhost:3010/studentsを押すとローカルで実行するにはRESTモジュールファイルにApp.jsをモジュールにリダイレクトする

students.js

module.exports = function (service) { 

    /** 
    * Retrives data from DB 
    */ 
    service.get('/mobile/students', function (req, res) { 
     res.set('Content-Type', 'application/json') 
       .status(200) 
       .json(DBHelper.getAllStudents()); 
    }); 

    service.post('/mobile/students', function (req, res) { 
     res.status(200).json(data); 
    }); 
}); 

を持っている私は、次のようapp.js

const express = require('express'); 
const app = express(); 

var routes = require('./students'); 
app.get('/', function (req, res) { 
    res.send('Hello World!') 
}); 

app.listen(3010, function() { 
    console.log('Example app listening on port 3010!') 
}); 

を使用しています404を表示しています。

学生モジュールへのパス?

あなたが var routes = require('./students');routes(app);行を追加する必要があり
+2

私はあなたを考えます'require( './ students')(app)'を実行する必要があり、 'http:// localhost:3010/mobile/students'にあなたの学生を連れて行くでしょうか? – codtex

+0

こんにちはCodtex、ありがとう。私はあなたにapp.jsにrequire( './ students)を追加するように頼んでいると思います。しかし、それはうまくいかなかった。 –

+0

申し訳ありませんが、私の間違いは( './ students')(app)が働いたことが必要です。それが実際に何を理解するのを助けてくれますか? –

答えて

1

その後、あなたのルートがマウントされます。.. http://localhost:3010/students使用であれば、これはそれが404で再びプロンプトが表示されますが、あなたはhttp://localhost:3010/mobile/studentsを使用している場合、それは欲望の出力を生成します。..

関連する問題