API routes are great for APIs, but for small projects where you have to access server data or hide application logic, you can just call a server function from the client.

Overview

function-apis

Pass functions to the client instead of API routes

API routes are great for APIs, but for small projects where you have to access server data or hide application logic, you can just call a server function from the client.

Examples

// Hide server logic

// Server
const functions = require('function-apis');
app.use(functions({
    hello: (name) => {
        return `Hello, ${name}!`;
    }
}, true));

// Client
hello('World').then(alert); // => 'Hello, World!'
// Log something to the console

// Server
const functions = require('function-apis');
app.use(functions({
    consoleLog: (...data) => {
        console.log(...data);
        return 'OK';
    }
}, true));

// Client
consoleLog('Hello!') // => 'OK'

Documentation

functions(functions, defineGlobally)

Use as express middleware. Default export.

* `functions`: Object of functions to expose to the client.
* `defineGlobally?`: Whether or not to define the functions globally. Defaults to `false`.

? Optional

window.functions

An object of client-side functions. Available after including the following in your HTML. If defineGlobally is set to true, the functions will be available to window[function] in addition to window.functions[function].

">
<script src="/functions_/functions.js">script>

yodacode.xyz

You might also like...

wasteof-client is an npm package for wasteof.money

wasteof-client is an npm package for wasteof.money

Jun 16, 2022

SiJago - GraphQL Client for Browser and Node.js

SiJago is GraphQL Client for Browser and Node.js, You can write request GraphQL schema using JavaScript Object Style, Why i create this tools, Because for reducing typo when writing GraphQL schema using HTTP client like Axios, Fetch or GraphQL client using Apollo and also to simplify calling the GraphQL schema easy to understand for human.

Mar 13, 2022

This is a facebook messenger clone.You can comminicate to other at realtime

This is a facebook messenger clone.You can comminicate to other at realtime

🟡 facebook-messenger This is a facebook messenger clone.You can comminicate to other at realtime 💬 ⚡ LIVE To check out the live demo of this app ABO

Sep 11, 2022

NatsirtMC is a lightweight app allowing you to connect to any Minecraft server without having Minecraft open

NatsirtMC the only way to grind without grinding NatsirtMC is a lightweight app allowing you to connect to any Minecraft server without having Minecra

Dec 26, 2022

Lazy-loading images with data-* attributes

Echo.js Echo is a standalone JavaScript lazy-loading image micro-library. Echo is fast, 2KB, and uses HTML5 data-* attributes for simple. Check out a

Dec 30, 2022

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

📝 Algorithms and data structures implemented in JavaScript with explanations and links to further readings

JavaScript Algorithms and Data Structures This repository contains JavaScript based examples of many popular algorithms and data structures. Each algo

Dec 31, 2022

TrackIt - Single Page Application that helps the user track their habits.

TrackIt - Single Page Application that helps the user track their habits.

TrackIt - Single Page Application that helps the user track their habits. Implemented with JavaScript/React and an API server which enables the user to sign-in or sign-up in the app.

Apr 13, 2022

Insider Unlocked is an ongoing web application

Insider Unlocked is an ongoing web application we have been co-developing for the past few months which aggregates stock trading data of US senators and presents it in a digestible manner for the average retail investor

Feb 13, 2022

NodeJS application to upload an image to a S3 Bucket on AWS.

NodeJS application to upload an image to a S3 Bucket on AWS.

node-upload-image-to-s3-bucket NodeJS application to upload an image to a S3 Bucket on AWS. How it works: You must make a POST request to /upload-imag

Sep 28, 2022
Releases(v1.0.1)
  • v1.0.1(Mar 6, 2022)

Owner
Web development, bots, developer tools, and other random JavaScript things
null
This web application retrieves real live data from the SpaceX API

This web application retrieves real live data from the SpaceX API. It provides commercial and scientific space travel services, by allowing users to book rockets and join selected space missions.

Sahar Abdel Samad 12 Aug 9, 2022
A personal home page for quick access to all your personal apps/sites

Fenrus Fenrus personal home page/dasbhoard. It allows you to have a custom home page/new tab page with quick access to your personal apps. For support

John Andrews 196 Dec 31, 2022
Gmail-like client-side drafts and bit more. Plugin developed to save html forms data to LocalStorage to restore them after browser crashes, tabs closings and other disasters.

Sisyphus Plugin developed to save html forms data to LocalStorage to restore them after browser crashes, tabs closings and other disasters. Descriptio

Alexander Kaupanin 2k Dec 8, 2022
Translate text to morse code, but the morse code is emojis

morsemoji Convert text to morse code... with emojis! Check it out! This project was built with React, Vite, Emoji Mart, Nord, and react-copy-to-clipbo

Cassidy Williams 48 Jul 21, 2022
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API

Huge thanks to for sponsoring me! Ky is a tiny and elegant HTTP client based on the browser Fetch API Ky targets modern browsers and Deno. For older b

Sindre Sorhus 8.5k Jan 2, 2023
A JavaScript, zero-dependency, super small version of IP2Location LITE country lookups.

A JavaScript, zero-dependency, super small version of IP2Location LITE country lookups.

Statsig 34 Dec 14, 2022
A simple server application that allows you to perform Wake-on-LAN remotely with a web interface

WoL Helper A simple server application that allows you to perform Wake-on-LAN remotely with a web interface. Usage Install: npm install -g wol-helper

Hongbo 5 Jul 27, 2022
💬 Real-time chat application prototype that can summarise the entire chat log

Chat summarizer ?? Disclaimer! This is a prototype and a fun project that I've been working on and it is not ready for production. It was done in a fe

null 5 Jan 22, 2022
A simple implementation of a task list application that can be used to add, remove, edit and check users tasks

"To-do list" is a tool that helps to organize daily activites. It simply lists the things which are needed to be done and allows user to mark them as complete. In this step of project, the CRUD (create, update, delete) methods are implemented. This simple web page is built using webpack and served by a webpack dev server.

Zahra Arshia 5 Mar 28, 2022
Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

Free, open-source crypto trading bot, automated bitcoin / cryptocurrency trading software, algorithmic trading bots. Visually design your crypto trading bot, leveraging an integrated charting system, data-mining, backtesting, paper trading, and multi-server crypto bot deployments.

Superalgos 3.1k Jan 1, 2023