简体   繁体   中英

Socket.io chat example node.js require

From the socket.io chat example.
What does it mean in the index.js:

var io = require('../..')(server);

What does '../..' means? I looked up the some information and some say that '../' means the index.js in the parent folder, is that correct?

I noticed that the index.js is missing require('socket.io')(server);

index.js:
var express = require('express');
var app = express();
var path = require('path');
var server = require('http').createServer(app);
var io = require('../..')(server);
var port = process.env.PORT || 3000;

so maybe ../.. require socket.io for us too?

Found same question on SO:

Here's the link

Basically ../ means moving into the parent directory of current directory.So the following line means ../.. will start searching the parent of parent directory will try to access server module form the same.

var io = require('../..')(server);

Suppose currently you are in Project/fol1/fol2 folder where index.js file is located,so if you want to require a module or file in project folder then you will have to move to the path first before accessing module "../.." this will do the same.

Please refer following link question answered by Adam you will get clear idea. node.js filesystem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM