Skip to content

Self.js: Self-contained web server running Javascript Universal applications.

License

Notifications You must be signed in to change notification settings

nmerouze/selfjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Self.js GoDoc

Wrapper around v8worker and net/http. Run Universal React applications faster than Node.js.

Setup

First you need to install v8worker. Then:

go get -u github.com/nmerouze/selfjs

Usage

import (
  "io/ioutil"
  "net/http"
  "runtime"

  "github.com/nmerouze/selfjs"
)

func main() {
  runtime.GOMAXPROCS(runtime.NumCPU())

  js, _ := ioutil.ReadFile("path/to/file.js")
  http.Handle("/", selfjs.New(runtime.NumCPU(), `
    selfjs.handleRequest = function(req, res) {
      res.write('Hello World!');
    }
  `))
  http.ListenAndServe(":8080", nil)
}

Example

cd example
npm install
npm run build
go run server.go
open http://localhost:8080

The application is rendered on the server. Both the client and the server share the same file (universal.js) with a few conditions to select the right rendering function. The code also runs on Node.js, just run node server.js. Self.js is 50% than Node.js while Node.js consumes 50% memory.

About

Self.js: Self-contained web server running Javascript Universal applications.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published