JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q42995F
  • License ISC

Call a remote function or method of a remote object from an Express App that can be shared to any frontend frameworks.

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-node

or

yarn add shared-node

CDN

<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 ]

Join and support our Community
Web and Mobile Developers PH
[ Facebook Page | Group ]