WebSockets(使用Socket.io)教程#2-创建Express应用程序



嗨,帮派,在此websockets教程中,我将向您展示如何在Node.js上启动并运行一个非常简单的Express应用程序,以准备使用websockets。

—–课程链接:
+回购-https://github.com/iamshaunjp/websockets-playlist
+ Atom编辑器-https://atom.io/a
+下载节点-https://nodejs.org/en/
+ Socket.io-https://socket.io
————————————————– ——————————————-
相关教程:

—– NODE.JS教程

—–订阅频道-https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg?sub_confirmation=1

==============网络忍者=====================

有关更多的前端开发教程并精通您的编码技能,请访问-https://www.youtube.com/channel/UCW5YeuERMmlnqo4oq8vwUpg或http://thenetninja.co.uk

==================社交链接==================

Twitter-@TheNetNin​​ja-https://twitter.com/thenetninjauk。

40 comments
  1. What is the font you're using on Atom? I know it's not a monospaced but it looks pretty neat and I want to use it in my website. Thanks!

  2. CSS:
    body{

    font-family: 'Nunito';

    }

    h2{

    font-size: 18px;

    padding: 10px 20px;

    color: #575ed8;

    }

    #mario-chat{

    max-width: 600px;

    margin: 30px auto;

    border: 1px solid #ddd;

    box-shadow: 1px 3px 5px rgba(0,0,0,0.05);

    border-radius: 2px;

    }

    #chat-window{

    height: 400px;

    overflow: auto;

    background: #f9f9f9;

    }

    #output p{

    padding: 14px 0px;

    margin: 0 20px;

    border-bottom: 1px solid #e9e9e9;

    color: #555;

    }

    #feedback p{

    color: #aaa;

    padding: 14px 0px;

    margin: 0 20px;

    }

    #output strong{

    color: #575ed8;

    }

    label{

    box-sizing: border-box;

    display: block;

    padding: 10px 20px;

    }

    input{

    padding: 10px 20px;

    box-sizing: border-box;

    background: #eee;

    border: 0;

    display: block;

    width: 100%;

    background: #fff;

    border-bottom: 1px solid #eee;

    font-family: Nunito;

    font-size: 16px;

    }

    button{

    background: #575ed8;

    color: #fff;

    font-size: 18px;

    border: 0;

    padding: 12px 0;

    width: 100%;

    border-radius: 0 0 2px 2px;

    }

  3. If I open a browser using chrome address http//:localhost:4000 I get a failed to load page. Doesn't work for me I'm afraid unless someone can help? I installed the Atom package to view in browser, but it took me to port 8081 for some reason. Manually changing it to 4000 also didn't work. Also why do I have a package-lock.json file?

  4. Hi apologies but can I ask if the files on your Git are still there? Because I'm trying to follow the tutorial but the only files that I see on the Git are gitignore and READme file. Would really appreciate if someone can help me out with this! Thanks for tutorial though! Really helpful so far.

  5. Thank you so much for this series! You have assisted me to get my Fishtank controller (using GPIO pins on a Raspberry Pi) started and I am stoked with the results. I struggled with some of the other tutorials I was trying to follow. Your simple example was clearly explained and easy to follow.

  6. var server = app.listen(4000.function(){

    ^^^^^

    SyntaxError: Invalid or unexpected token

    at new Script (vm.js:79:7)

    at createScript (vm.js:251:10)

    at Object.runInThisContext (vm.js:303:10)

    at Module._compile (internal/modules/cjs/loader.js:656:28)

    at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)

    at Module.load (internal/modules/cjs/loader.js:598:32)

    at tryModuleLoad (internal/modules/cjs/loader.js:537:12)

    at Function.Module._load (internal/modules/cjs/loader.js:529:3)

    at Function.Module.runMain (internal/modules/cjs/loader.js:741:12)

    at startup (internal/bootstrap/node.js:285:19)

  7. Yoh Shaun, i have a question: When you make a chat app, do you host the server app? If yes how would the url look, so that its inaccessible through a normal browser, and that it is only accessible through the mobile app and the client website that contains the chat app that the users can use? Thanks for the videos, they're awesome
    PS if Shaun doesn't reply or if you see this before him, please help out if you know whats happening here

  8. I have a doubt. When i do app.use(express.static('public')); , why does it not work unless the html file in the public folder is named index.html?? i tried renaming file to st.html but when i run on the browser, it says CANNOT GET/. it only works when it is index.html

  9. Hi. I'm following this tutorial line by line. I noticed when I run nodemon, it returns a message saying that nodemon is not recognized. How do I fix that?

Comments are closed.