English 中文(简体)
页: 1 io not working on heroku
原标题:socket.io not working on heroku

每当我试图使用<代码>require(“socket.io”)时,就座标语“Cannot发现模块袖珍”。

我认为,这是我的一个问题,因为在我的当地天候服务器上,情况也是如此。

我必须改变什么?

最佳回答
问题回答

页: 1

"dependencies": {
"async":     "0.1.18",
"ejs":       "0.4.3",
"express":   "2.4.6",
"faceplate": "0.0.4",
"socket.io": "latest"   },

服务器代码为:

var port=process.env.PORT || 3000;
var http=require( http );
var app=http.createServer(function(req,res){
    res.write("server listening to port:"+port);
    res.end();
}).listen(port);
socket=require("socket.io");
io=socket.listen(app);
io.configure(function () { 
  io.set("transports", ["xhr-polling"]); 
  io.set("polling duration", 10); 
});
io.sockets.on("connection",function(socket){
    console.log("new connection");
    socket.on("eventA",function(data){
        io.sockets.emit("eventB",data);
    }); 
});

!

你们需要改变运输选择。 根据

网上运输正在按州Heroku进行。 您可以使用<代码>heroku labs:可浏览的网页目录。 - APP_NAME

这些都是有待解决的问题。 2. 与环境有关的问题

我希望我能够工作。

  1. Ports in your (index.js or server.js) & (index.html and your client.js) port must be different. (refer below code)

=============your index.js file ======================

(此处为8000)

const express = require("express")
var app = express();
const http = require( http )
var server = http.createServer(app);
  
const port = process.env.PORT || 8000
server.listen(port,()=>
{
    console.log("Listening at port => "+port)
});
var io = require( socket.io )(server, {
    cors: {
      origin:  * ,
    }
});

const cors = require("cors")
app.use(cors()) 

===========your 客户档案 ================================================================================================================================================================================================================================================================

港口:8080

const socket = io.joint(电话:1) http:// localhost:8080/ iii

===========your 指数.html ================================================================================================================================================================================================================================================================

港口:8080

 <script defer src="https://localhost:8080/socket.io/socket.io.js"> 
 </script>

回收你的“服务器、js或index.js”港口应与“客户”港口不同(这一点很重要)。

(指数.html和客户.js)港口必须相同。

  1. 你们总是使用http://www.un.org。 io(见上文代码)

  2. U可能不包括 co,因为它使u能够拥有更多的资源,而没有rs子会阻止一些附属公司不在其oku(见上文代码)安装。

  3. 将“O”改为“io.link”。

    const socket = io.joint(电话:1) http:// localhost:8080/ iii

  4. 最终必须用超文本书写标签

  5. 美国可能忘记,在“备注”中加入这一法典。

页: 1

  1. delete "node_modules" and "package-lock.json" and write "npm i" in cmd

  2. This should be in package.json s scripts

    “启动”:“node index.js”,

I am not talking about nodemon , use simple node over here

  1. 也许版本正在形成一个问题,u 可以通过将所有“发展中国家”复制到“包装......json”中的“独立性”来避免这一问题,并将“*”文本照样。

    “独立性”: 页: 1

    “准则”:“*”

    “表示”:“*”

    “无”:“*”

    “s agenda.io”:“*”

    },

    dev "Depends”.{}





相关问题
Packaging precompiled binaries inside of a gem

I ve got a ruby web app that uses lilypond to generate sheet music based on user input. I d like to move the hosting to heroku (I ve recently used heroku on a few projects and really liked it, plus ...

ActiveScaffold on Heroku s read-only file system?

ActiveScaffold apparently creates public/blank.html every time the server starts, even if that file already exists (so adding it to version control doesn t help). This is causing my application to ...

git push heroku master permission denied on VISTA

(Using Vista)I m trying to clone an app from my GitHub Repository and push it into Heroku. Okay, so I ve tried to create an SSH key so many times with this: `ssh-keygen -t rsa` It seems to go ...

SSH Public key denied on "git clone" command

I am trying to clone a git repo that I forked in my GitHub Repository.It s a rails app. I want to clone it on my local git so that I can push it onto heroku. I generated a set of rsa keys and copied ...

heroku using git branch is confusing!

Ok, so I have a big github project that i m not supposed to merge my little Stacia branch into. However, it seems like Heroku only takes pushing MASTER seriously. It looks like I pushed my branch, but ...

PostgreSQL GROUP BY different from MySQL?

I ve been migrating some of my MySQL queries to PostgreSQL to use Heroku. Most of my queries work fine, but I keep having a similar recurring error when I use group by: ERROR: column "XYZ" must ...

热门标签