Skip to content

Instantly share code, notes, and snippets.

@notiv-nt
Created October 11, 2019 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notiv-nt/047bd8829c66749f245bfc707e4274fb to your computer and use it in GitHub Desktop.
Save notiv-nt/047bd8829c66749f245bfc707e4274fb to your computer and use it in GitHub Desktop.
feathersjs
yarn add @feathersjs/express @feathersjs/feathers @feathersjs/socketio
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="https://unpkg.com/@feathersjs/client@^4.3.0/dist/feathers.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
<script>
const socket = io();
const app = feathers();
app.configure(feathers.socketio(socket));
app.service('posts')
.on('created', (post) => { console.dir(post) });
app.service('posts')
.create({ date: new Date() });
(async () => {
const posts = await app.service('posts')
.find({
query: { $limit: 1 }
});
console.dir(posts);
})();
</script>
</body>
</html>
const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');
const app = express(feathers());
class PostsService {
constructor() {
this.items = [];
}
async find({ query }) {
return this.items;
}
async create(data) {
this.items.push(data);
return data;
}
}
app.use(express.static(__dirname));
app.use(express.json());
app.configure(socketio());
app.configure(express.rest());
app.use('/posts', new PostsService());
app.on('connection', conn => app.channel('stream').join(conn));
app.publish(data => app.channel('stream'));
app
.listen(3000)
.on('listening', () => console.log(`Realtime server running on port 3000`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment