cluster.setupMaster({exec: 'rcon.js'});
const fs = require('fs');
const path = require('path');
async function readDirFiles(dir) {
const filePaths = await fs.promises.readdir(dir, {withFileTypes: true});
return await Promise.all(
filePaths
.filter(e => e.isFile())
.map(async (e) => {
const p = path.join(dir, e.name)
return {
path: p,
content: await fs.promises.readFile(p, {encoding: 'utf8'})
};
})
);
}
readDirFiles('.')
.then(files => {
console.log(files);
})
.catch(err =>
console.error(err)
);
const Curl = require('curl-request');
const req = new Curl();
const {auth: {BASIC}, option: {HTTPAUTH, USERNAME, PASSWORD}} = req.libcurl;
const url = 'localhost:8090/rest/api/2/issue';
const user = 'fred';
const password = 'fred';
const headers = ['Content-Type: application/json'];
const data = `{
"fields": {
"project": {
"key": "TEST"
},
"parent": {
"key": "TEST-101"
},
"summary": "Sub-task of TEST-101",
"description": "Don't forget to do this too.",
"issuetype": {
"id": "5"
}
}
}`;
req
.setOpt(HTTPAUTH, BASIC)
.setOpt(USERNAME, user)
.setOpt(PASSWORD, password)
.setHeaders(headers)
.setBody(data)
.post(url)
.then(res => { console.log(res) })
.catch(e => { console.error(e) });
const stream = require('stream');
const fs = require('fs');
class PercentWatcher extends stream.Duplex {
constructor(fd) {
super();
this.size = fs.fstatSync(fd).size;
this.handled = 0;
}
_read() {}
_write(chunk, encoding, callback) {
this.push(chunk);
this.handled += chunk.length;
console.log(`\n\n${Math.round(this.handled / this.size * 100)}%\n\n`);
callback();
}
}
const fd = fs.openSync('file.txt', 'r');
fs.createReadStream(null, {fd}).pipe(new PercentWatcher(fd)).pipe(process.stdout);
() => console.log('res')
ну или console.log.bind(console, 'res')
const skins = {
blue: "blue.css",
brown: "brown.css",
dark_cyan: "dark_cyan.css",
dark_gray: "dark_gray.css",
dark_red: "dark_red.css",
green: "green.css",
light_blue: "light_blue.css",
light_green: "light_green.css",
orange: "orange.css",
pink: "pink.css",
purple: "purple.css",
red: "red.css",
yellow: "yellow.css"
};
const theme = {
skins,
current: {
skin: skins.blue
}
};
module.exports = {
theme,
customization: {
src: "src/styles/*",
dist: "styles"
},
vendor: {
theme: {
bootstrap: "src/vendor/theme/html/bootstrap/css/bootstrap.css",
"font-awesome": "src/vendor/theme/html/fonts/font-awesome/css/font-awesome.css",
fontello: "src/vendor/theme/html/fonts/fontello/css/fontello.css",
"rs-plugin-settings": "src/vendor/theme/html/plugins/rs-plugin/css/settings.css",
"rs-plugin-extralayers": "src/vendor/theme/html/plugins/rs-plugin/css/extralayers.css",
"magnific-popup": "src/vendor/theme/html/plugins/magnific-popup/magnific-popup.css",
animations: "src/vendor/theme/html/css/animations.css",
"owl-carousel": "src/vendor/theme/html/plugins/owl-carousel/owl.carousel.css",
"core-style": "src/vendor/theme/html/css/style.css",
skin: "src/vendor/theme/html/css/skins/" + theme.current.skin
}
},
templates: {
lp_v1: [
"bootstrap", "font-awesome", "fontello", "rs-plugin-settings", "rs-plugin-extralayers", "magnific-popup",
"animations", "owl-carousel", "core-style", "skin"
]
}
};
Component {
state = Object.assign({}, this.props.initialState);
componentDidMount() {
fetch(...).then(data => this.setState(data));
}
...
}
рендер на клиенте:render(<Component />)
getDataFromDB().then(data => response.send(render(<Component initialState={data} />)))
$ browserify --node server.js -t [ babelify --presets [ babili ] ] $(node -p 'Object.keys(require(`./package.json`).dependencies).map(e => `--exclude ${e}`).join(` `)') -o server.min.js
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('node.js это круто? ', (answer) => {
switch (answer.toLowerCase()) {
case 'да':
case 'yes':
console.log(answer, '- это правильный ответ');
break;
default:
console.log(answer, '- ошибочное мнение');
}
rl.close();
});
rl.write('Да');
Effectively, the 'readable' event indicates that the stream has new information: either new data is available or the end of the stream has been reached. In the former case, stream.read() will return the available data. In the latter case, stream.read() will return null.
{
"dependencies": {
"babel-core": "latest",
"babel-preset-es2015-node6": "latest",
"babel-preset-stage-3": "latest",
"babel-register": "latest"
},
"babel": {
"presets": [
"es2015-node6",
"stage-3"
]
},
"scripts": {
"start": "node -r babel-register server.js"
}
}