This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const http = require('http') | |
| const app = new http.Server() | |
| app.on('request', (req, res) => { | |
| res.writeHead(200, { 'Content-Type': 'text/plain' }) | |
| res.write('Hello World') | |
| res.end() | |
| }) | |
| app.listen(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const service = require('restana')({}) | |
| service.get('/hi', (req, res) => { | |
| res.send('Hello World!') | |
| }) | |
| service.start() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express') | |
| const app = express() | |
| app.get('/hi', (req, res) => { | |
| res.send('Hello World!') | |
| }) | |
| app.listen(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const N = 2000000 | |
| const items = [] | |
| for (var i = 0; i < N; i++) { | |
| items.push({ index: i }) | |
| } | |
| console.log(items.map(e => e.index).filter(v => v % 2 === 0).reduce((sum, v) => sum += v)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express') | |
| const bodyParser = require('body-parser') | |
| const axios = require('axios') | |
| const httpc = axios.create({ | |
| baseURL: 'http://localhost:3000', | |
| timeout: 30000 | |
| }) | |
| const app = express() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const server = require('express')({}) | |
| server.get('/', (req, res) => { | |
| res.send('Hello World!') | |
| }) | |
| server.listen(3000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (async () => { | |
| const Client = require('hazelcast-client').Client | |
| const hz = await Client.newHazelcastClient() | |
| const list = hz.getList('my-distributed-list') | |
| await list.add(process.pid) | |
| console.log(await list.toArray()) | |
| await hz.shutdown() | |
| })() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // on application instance start... | |
| const counter = hazelcast.getAtomicLong('distributed-pushes-counter') | |
| await counter.compareAndSet(0, await PushLogs.count({})) | |
| // on push... | |
| await counter.incrementAndGet() | |
| // on request | |
| await counter.get() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const lock = hazelcast.getLock('my-distributed-lock') | |
| lock.lock().then(() => { | |
| // the execution of this function will happen once | |
| // at a time across all distributed instances | |
| // ... | |
| console.log('Happy Locking!') | |
| }).finally(() => lock.unlock()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // on application instance start, init near cache Map | |
| const {Client, Config} = require('hazelcast-client') | |
| const nearCachedMapName = 'my-holy-fast-map' | |
| const cfg = new Config.NearCacheConfig() | |
| cfg.name = nearCachedMapName | |
| cfg.invalidateOnChange = true | |
| cfg.nearCacheConfigs[nearCachedMapName] = cfg | |
| const hazelcast = await Client.newHazelcastClient(cfg) |
OlderNewer