zach.codes

zach.codes

Share this post

zach.codes
zach.codes
NodeJS on the Frontend
Copy link
Facebook
Email
Notes
More

NodeJS on the Frontend

What if you could import a generic NodeJS function into your frontend code? I'll show you how I made it possible.

Zach Silveira
Jul 24, 2020
∙ Paid

Share this post

zach.codes
zach.codes
NodeJS on the Frontend
Copy link
Facebook
Email
Notes
More
Share
NodeJS on the Frontend

What if we could import a generic NodeJS function into our frontend code? In this example, statuses returns results from Firestore.

import { statuses } from './statuses.server.js'

export const Statuses = () => {
  
  if(loading) return <div>Loading...</div>
  
  return (
      <div
        onClick={() => {
          let statuses = await statuses('timeline')
          console.log(statuses)
        }}
      >
        Load Statuses
      </div>
  )
}

Instead of writing network requests, wouldn't it be nice to write full stack code, and import it like a normal part of the frontend? Keep reading to find out how I got this working in a real application.

Contents

  • What is it

  • GRPC inspired

  • How I made this work

  • Server Loader

  • Node Setup

  • Recap

  • Final Thoughts

How things are done currently

In traditional apps, our frontend might have a file called Statuses.js that looks like this:

import React from 'react'

export const Statuses = () => {
  let statuses = ['first', 'second', 'third']
  
  return statuses.map…

Keep reading with a 7-day free trial

Subscribe to zach.codes to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Zach Silveira
Privacy ∙ Terms ∙ Collection notice
Start writingGet the app
Substack is the home for great culture

Share

Copy link
Facebook
Email
Notes
More