有问题的代码是app.use(express.static("web"))
行。
var express = require('express')();
var app = express();
var http = require('http').Server(app);
var io = require('socket.io')(http);
//app.get('/', function(res, req) {
// res.sendFile(__dirname + '/www/index.html');
//})
app.use(express.static("web"));
在控制台中返回以下错误:
/Users/matthewwalker/CVLGBT/CVLGBT/www/node_modules/finalhandler/index.js:92
if (!err && res._header) {
^
TypeError: Cannot read property '_header' of undefined
at /Users/matthewwalker/CVLGBT/CVLGBT/www/node_modules/finalhandler/index.js:92:21
at Function.handle (/Users/matthewwalker/CVLGBT/CVLGBT/www/node_modules/express/lib/application.js:170:5)
at app (/Users/matthewwalker/CVLGBT/CVLGBT/www/node_modules/express/lib/express.js:38:9)
at Object.<anonymous> (/Users/matthewwalker/CVLGBT/CVLGBT/www/index.js:2:11)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
其他时候我稍微修改代码会得到express is not defined
。文件结构:index.js和节点模块在根目录下,而所有html / css / js / imgs在/ web下。我不确定为什么会引发此标头标志。当我使用app.get
行时,它仅发送html文件,而不发送图像或js。我需要能够提供/ web的整个目录。
答案 0 :(得分:4)
您要在第一行中构建一个import math
class Vector:
def __init__(self,x,y):
self.x= x
self.y =y
def add(self,other):
new_x = self.x + other.x
new_y = self.y + other.y
return Vector(new_x,new_y)
def subtract(self,other):
new_x = self.x - other.x
new_y = self.y - other.y
return Vector(new_x,new_y)
def scale(self,factor):
new_x = self.x * factor
new_y = self.y * factor
return Vector(new_x,new_y)
def length(self,other):
r_squared = self.x ** 2 + self.y **2
return Vector(r_squared)
实例,然后在第2行中调用它:
app
您应该改为这样做:
var express = require('express')();
var app = express();
或者这个:
var express = require('express');
var app = express();
您可以找到有关express api here的更多信息。