const tty = require('tty');
if(tty.isatty(0)) {
process.stdin = new tty.ReadStream();
} else {
//init process.stdin from other stream
}
var outStream;
if(tty.isatty(1)) {
outStream = new tty.WriteStream();
process.stdout = outStream;
} else {
//init process.stdout from other stream
}
if(tty.isatty(2)) {
if(!outStream) {
outStream = new tty.WriteStream();
}
process.stderr = outStream;
} else {
//init process.stderr from other stream
}
socket.emit('register');
уронит ваш сервер с ошибкой, так как data будет undefined (null и undefined не могут иметь свойств)const LOGIN_REGEX = /[^a-zA-Z0-9]/; //скомпилим регулярку заранее, дабы не компилить при каждом запросе
socket.on('register', function(data){
if(!data || typeof data.login !== 'string') { return; } //проверка на наличие и правильный тип
if(data.login.length < 4 || data.login.length > 12) { return; } //проверка на допустимую длину, числа ставьте свои
if(LOGIN_REGEX.test(data.login)) { return; } // такая проверка в 18 раз быстрее чем у Вас
new User({login: data.login}).save();
});
но как известно она не прям идеально подходит для отдачи статикиУ меня на сервере нода торчит наружу и отдает статику, притом делает это шустрее nginx и жрет меньше памяти, все зависит от рук программиста
function checkSpec() {
return driver.executeScript("var search = []; if (typeof xmlDataSpeclist !== 'undefined') {" +
"$.each(xmlDataSpeclist, function (key, item) {" +
"search.push(" +
"'http://domain/?spec='" + " + item.id" +
");" +
"});" +
"};" +
"return search;"
).then((search) => {
return Promise.all(search.map(function(val, i) {
console.log(search.length); //debug printing
return new Promise((resolve, reject) => {
request(search[i], function(error, response, body){
if (error) {
reject(error);
}
resolve(body);
});
}).then((body) => {
console.log(body);
assert.include(body, 'class="someClass"');
});
}));
});
}
return checkSpec();
const request = require('request');
const FeedParser = require('feedparser');
function readFeed(url) {
return new Promise((resolve, reject) => {
const $this = this;
const feedParser = new FeedParser();
const req = this.request(url);
feedParser.on('readable', function() {
var stream = this, item = stream.read();
if (item) {
//код для работы с данными
}
});
this.feedParser.on('end', () => {
resolve();
});
feedParser.on('error', reject);
req.on('response', function(res) {
req.pipe(feedParser);
});
req.on('error', reject);
});
}
readFeed('url').then(() => {
console.log('end');
});
(function(module, require, exports) {
// код модуля вставляется сюда
});
var module = new Module(pathToModuleFile);
var moduleFunction = loadCodeAndRunInVM(module.id);
moduleFunction(module, module.require, module.exports); //Выполнили модуль
cache[module.id] = module.exports;
return module.exports;