I
I
Ingerniated2017-02-17 01:34:17
Node.js
Ingerniated, 2017-02-17 01:34:17

How to write a server on node?

Comrades, tell me, I got into a situation that I’m reading an article, they seem to understand it clearly, but I don’t understand the essence of what the server should consist of, what it should include, what logic it should use in order to be able to work.
What book or article is worth reading in order to understand what I need and what functions to use, what to try to achieve from the server so that it does.
According to this example, I was able to start the server with only one file, which cannot have css or js files if they are connected to it.
www.nodebeginner.ru

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vyacheslav Belyaev, 2017-02-17
@Ingernirated

I'll tell you from scratch

  1. You install Node. I use this https://nodejs.org/en/download/package-manager/#de...
  2. On the server you create a file (for example server.js)
  3. You install modules where the js file is located (for example "npm install express")
  4. In the file itself write something like this
    var express = require('express');
    var app = express();
    var http = require('http');
    
    var server = http.createServer();
    var io = require('socket.io').listen(server, options);
    server.listen('3636');
    
    
    io.on("connection", function (socket) {
    
    //Сюда параметры подключения
    
    })

  5. Well, you run the node server.js file
  6. Well, then you expand it to suit your task.

V
Vasily Nazarov, 2017-02-18
@vnaz

unable to include css and js files
Because they connect in the browser, not on the server.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question