Package Exports
- shared-node
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (shared-node) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Welcome to shared-node!
Directly call a function or method of a remote object that can be shared with any frontend frameworks.
Installation
npm install shared-nodeor
yarn add shared-nodeCDN
<script src="https://unpkg.com/shared-node/dist/index.js"></script>Server
// Server.js
const express = require('express')
const app = express()
const bodyParser = require('body-parser')
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
const cors = require('cors')
app.use(cors())
app.listen(3000)
class Person {
constructor() {
this.name = 'Trinmar Pogi'
}
run(speed) {
return `${this.name} is running at ${speed}km/h`
}
eat(food) {
return `${this.name} is eating ${food}`
}
talk(speech) {
return speech
}
}
let human = new Person('Trinmar Pogi')
// see the magic here 🧙
const { sharedCodeServer } = require('shared-node')
app.use(sharedCodeServer({ human }))Client
async function init () {
const { sharedCodeClient } = require('shared-node')
// const { sharedCodeClient } = sharedNode // for CDN
const { human } = await sharedCodeClient('http://localhost:3000')
console.log(await human.run(100)) // Mr. Pogi is running at 100km/h
}
init()Join and support our Community
Web and Mobile Developers PH
[ Facebook Page | Group ]