我无法从本地主机获得响应

时间:2020-09-15 11:07:53

标签: javascript node.js json express nodemon

我创建了一个app.js和一个controller.js,它以前曾经工作过,但是现在我无法获得响应

app.js

var express = require('express');
var app = express();
var path = require('path');
var ctrlElektronik = require('./ElektronikController'); 
app.use('/public',express.static(path.join(__dirname, 'public')));
app.get('/elektronik',ctrlElektronik.index);
app.get('/elektronik/bilgisayar',ctrlElektronik.bilgisayar);

app.listen(8000);

ElektronikController.js

var path = require('path');
module.exports.index = function(req,res){
    res.sendFile(path.join(__dirname,'index.html'));
    res.end();
}
module.exports.bilgisayar = function(req,res){
    res.sendFile(path.join(__dirname,'login.html'));
    res.end();
}

package.json

{
    "name": "nodedeneme",
    "version": "1.0.0",
    "scripts": {
        "start": "nodemon app.js"
    },
    "dependencies": {
        "express": "^4.17.1"
    }
}

index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <link rel="stylesheet" href="/public/css/style.css">
    </head>
    <body>
    <h1 class="deneme">VS Code</h1>
    <p class="deneme">Hello</p>
    </body>
</html>

我认为app.js中的ctrlElektronik变量可能存在问题

0 个答案:

没有答案