Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nmerouze/selfjs
Self.js: Self-contained web server running Javascript Universal applications.
https://github.com/nmerouze/selfjs
Last synced: 16 days ago
JSON representation
Self.js: Self-contained web server running Javascript Universal applications.
- Host: GitHub
- URL: https://github.com/nmerouze/selfjs
- Owner: nmerouze
- License: mpl-2.0
- Created: 2015-06-19T02:19:37.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-01T08:24:27.000Z (over 8 years ago)
- Last Synced: 2024-10-14T19:43:02.679Z (about 1 month ago)
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 56
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - selfjs - Self.js: Self-contained web server running Javascript Universal applications. (Go)
README
# Self.js [![GoDoc](https://godoc.org/github.com/nmerouze/selfjs?status.png)](https://godoc.org/github.com/nmerouze/selfjs)
Wrapper around [v8worker](https://github.com/ry/v8worker) and `net/http`. Run Universal React applications faster than Node.js.
# Setup
First you need to install [v8worker](https://github.com/ry/v8worker). Then:
```
go get -u github.com/nmerouze/selfjs
```# Usage
``` go
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.