[Node. js] minor errors that have to be prevented in windows

Source: Internet
Author: User
Tags sendfile
TypeError: Argumentstopathjoinmustbestringsatf (pathjs: 204: 15) atObjectfilter (native) atexportsjoin (pathjs: 209: 40) atexportssend (

TypeError: Arguments to path.join must be strings    at f (path.js:204:15)    at Object.filter (native)    at exports.join (path.js:209:40)    at exports.send (E:\nodejs\demo\socket.io-express\node_modules\express\node_modules\connect\lib\middleware\static.js:129:20)    at ServerResponse.res.sendfile (E:\nodejs\demo\socket.io-express\node_modules\express\lib\response.js:186:3)    at io.sockets.on.socket.emit.text (E:\nodejs\demo\socket.io-express\app.js:8:6)    at callbacks (E:\nodejs\demo\socket.io-express\node_modules\express\lib\router\index.js:272:11)    at param (E:\nodejs\demo\socket.io-express\node_modules\express\lib\router\index.js:246:11)    at pass (E:\nodejs\demo\socket.io-express\node_modules\express\lib\router\index.js:253:5)    at Router._dispatch (E:\nodejs\demo\socket.io- express\node_modules\express\lib\router\index.js:280:5)

When the two modules Socket. io and Express in Node. js are integrated, the following error occurs:


var express = require('express');var app = module.exports = express.createServer(),    io = require('socket.io').listen(app); app.listen(3000); app.get('/', function(req, res){    res.sendfile(__dirname + '/index.html');}); io.sockets.on('connection', function(socket){    socket.emit('welcome', {text: 'OH HAI! U R CONNECTED!'});});

Error cause:

The main cause of the error is that the above Code is 8th lines. You can simply change the code to the following format.

var express = require('express');var app = module.exports = express.createServer(),    io = require('socket.io').listen(app);app.listen(3000);app.get('/', function(req, res){res.sendfile('/index.html', {root: __dirname});});io.sockets.on('connection', function(socket){socket.emit('welcome', {text: 'OH HAI! U R CONNECTED'});});


Upload under win

_ Dirname + '/index.html'-> E: \ nodejs \ demo/index.html

It seems that the url parsing module is used there. The final parsing result is not like the path in windows ..

The path is incorrect when the stream is created ..

References: https://github.com/visionmedia/send


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.