js file,
app.get('/',function(req,res){
res.sendfile(_dirname + '/index.html');
});
node.js can start ,but I got this error,
ReferenceError: path is not defined at Object.handle (E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\app.js:12:15) at next_layer (E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\node_modules\express\lib\router\route.js:103:13) at Route.dispatch (E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\node_modules\express\lib\router\route.js:107:5) at E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\node_modules\express\lib\router\index.js:195:24 at Function.proto.process_params (E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\node_modules\express\lib\router\index.js:251:12) at next (E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\node_modules\express\lib\router\index.js:189:19) at Layer.expressInit [as handle] (E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\node_modules\express\lib\middleware\init.js:23:5) at trim_prefix (E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\node_modules\express\lib\router\index.js:226:17) at E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\node_modules\express\lib\router\index.js:198:9 at Function.proto.process_params (E:\javaEEstudy\node.js\node.js入门经典\socket\socket.io_express\node_modules\express\lib\router\index.js:251:12)
the index.html and app.js is on the same file ,express version is 4.x
First you should use
res.sendFile()
instead of
res.sendfile()
Second, the parameter of the above-mentioned method should be
__dirname+'index.html'
instead of
_dirname+'index.html'
In other words
app.get('/',function(req,res){
res.sendFile(__dirname + '/index.html');
});
Also you have to declare path
in your Node.js app:
var path = require("path");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With