[node. js] has to prevent minor errors under windows

Source: Internet
Author: User
Tags emit sendfile

Typeerror:arguments to Path.join must is 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)

The following error occurred when the two modules in node. js were integrated with Express Socket.io:


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! '});

Cause of Error:

The basic cause of the error is the line 8th above, which changes the code to work in the following form.

var express = require (' Express '), var app = Module.exports = Express.createserver (),    io = require (' Socket.io '). Listen (app); app.listen; 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 '});


In win down the pass

__dirname + '/index.html ' - e:\nodejs\demo/index.html

Seemingly, there is a URL parsing module. The result of the final parsing is not the way Windows looks like:

The path is not correct until the stream is created.

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


Related Article

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.