gpt4 book ai didi

node.js - GET http ://localhost:3000/lib/angular/angular. js 未找到错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:07:28 24 4
gpt4 key购买 nike

enter image description here enter image description here下面我上传了我的index.html、package.json、server.js、app.js 和MainController.js。运行 Node 服务器后,我只得到index.html。但index.html需要angular.js、app.js、MainController.js。在我的控制台中,我收到“GET http://localhost:3000/lib/angular/angular.js”未找到错误。

任何人都可以帮我解决这个问题吗?

    <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prettyprint-override"><code>
//package.json


{
"name": "ng-include",
"version": "1.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"body-parser": "^1.17.1",
"consolidate": "^0.14.5",
"express": "^4.15.2",
"html": "^1.0.0",
"swig": "^1.4.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "mehadi",
"license": "UNLICENSED",
"repository": {
"type": "git",
"url": "(https://github.com/mehadi07/JavaScript_Projects/AngularJS/ng-include)"
},
"devDependencies": {}
}


// server.js

var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var cons = require('consolidate');

var app = express();

app.engine('html', cons.swig);

app.set('view engine', 'html');

app.set('views', path.join(__dirname, 'views'));

app.use(express.static(path.join(__dirname, 'lib/')));


app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));


app.get('/',function(req,res){
res.render('index');
});

// Binding express app to port 3000
app.listen(3000,function(){
console.log('Node server running @ http://localhost:3000')
});

//app.js

'use strict';

// Declare app level module which depends on views, and components
var app = angular.module('loginApp', []);


enter code here

// MainController.js

app.controller('MainController', function MainController($scope) {

var employees = [
{
name: "Ben",
gender: "Male",
salary: 55000,
city: "London"
},
{
name: "Sara",
gender: "Female",
salary: 68000,
city: "Chennai"
},
{
name: "Mark",
gender: "Male",
salary: 57000,
city: "London"
},
{
name: "Pam",
gender: "Female",
salary: 53000,
city: "Chennai"
},
{
name: "Todd",
gender: "Male",
salary: 60000,
city: "London"
},
];

$scope.employees = employees;
$scope.employeeView= "employeeTable.html";
$scope.employeeList="employeeList.html";
});


</code></pre>
<pre class="snippet-code-html lang-html prettyprint-override"><code>
//index.html

<!DOCTYPE html>
<html lang="en" ng-app="loginApp" class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>AngularJS App</title>
<link rel="stylesheet" href="main.css">
</head>

<body ng-controller="MainController">
<div ng-include="'employeeTable.html'"></div>

<br/> Select View:
<select ng-model="employeeView">
<option value="employeeTable.html"> Table </option>
<option value="employeeList.html"> List </option>

</select>
<br/>
<br/>
<div ng-include="employeeView"></div>
<!--Created a scope on controller and shortend the .html format to a normal name
-->



<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-route.js"></script>
<script src="app.js"></script>
<script src="MainController.js"></script>

</body>

</html>


</code></pre>
</div>
</div>

最佳答案

更新了 server.js 文件并现已解决

app.set('views', path.join(__dirname, '/'));

// remove dir name to server anyfile
//app.use(express.static(path.join(__dirname, '/views/lib')));
app.use(express.static(path.join(__dirname)));

关于node.js - GET http ://localhost:3000/lib/angular/angular. js 未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43690111/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com