Skip to content

Instantly share code, notes, and snippets.

View nairihar's full-sized avatar
😎
Always busy

Nairi Harutyunyan nairihar

😎
Always busy
View GitHub Profile
@nairihar
nairihar / async-await.js
Created September 26, 2022 18:16
Three ways to work with File System in Node.js | Async / Await
const fs = require('fs/promises');
(async () => {
const data = await fs.readFile('LICENSE.md');
try {
await fs.writeFile('README.md', 'This is awesome!');
} catch (err) {
// ...
}
@nairihar
nairihar / promises.js
Created September 26, 2022 18:09
Three ways to work with File System in Node.js | Promises
const fs = require('fs/promises');
fs.readFile('LICENSE.md')
.then(data => {
// ...
})
.catch(err => {
// ...
});
@nairihar
nairihar / sync.js
Created September 26, 2022 18:01
Three ways to work with File System in Node.js | Sync functions
const fs = require('fs');
const data = fs.readFileSync('LICENSE.md');
try {
fs.writeFileSync('README.md', 'This is awesome!');
} catch (err) {
// ...
}
@nairihar
nairihar / callbacks.js
Created September 26, 2022 17:44
Three ways to work with File System in Node.js | Callbacks
const fs = require('fs');
fs.readFile('LICENSE.md', (err, data) => {
// ...
});
fs.writeFile('README.md', 'This is awesome!' (err) => {
// ...
});
@nairihar
nairihar / publisher.js
Created July 14, 2022 19:44
Scaling up Node.js Socket Server with Nginx and Redis | subscriber.js & publisher.js
const redis = require('redis');
const publisher = redis.createClient();
publisher.publish('my channel', 'hi');
publisher.publish('my channel', 'hello world');
@nairihar
nairihar / nginx.conf
Created July 14, 2022 19:31
Scaling up Node.js Socket Server with Nginx and Redis | nginx.conf
upstream nodes {
ip_hash;
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
}
@nairihar
nairihar / index.html
Last active July 14, 2022 19:20
Scaling up Node.js Socket Server with Nginx and Redis | index.html & server.js
<!Doctype html>
<html>
<head>
<title>Hello World</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.1.1/socket.io.js"></script>
<script>
const socket = io('http://0.0.0.0:3000', {
transports: ['polling']
// transports: ['websocket']
});
@nairihar
nairihar / nginx.conf
Created July 14, 2022 19:10
Scaling up Node.js Socket Server with Nginx and Redis | nginx.conf
upstream nodes {
server 127.0.0.1:8000;
server 127.0.0.1:8001;
server 127.0.0.1:8002;
}
server {
listen 3000;
location / {
@nairihar
nairihar / server.js
Last active July 14, 2022 19:09
Scaling up Node.js Socket Server with Nginx and Redis | server.js
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.end(`Hi, PID: ${process.pid}`);
});
app.listen(process.env.PORT);
console.log(`Server running on ${process.env.PORT} port, PID: ${process.pid}`);
@nairihar
nairihar / index.html
Created March 29, 2020 15:57
JavaScript Armenia | Store | LIVE session #3 | AM
<html>
<head>
<title>Store</title>
<link rel="stylesheet" href="./style.css">
</head>
<body>
<div id="StoreItems"></div>
<div id="User"></div>
</body>
<script src="./user.js"></script>