Add express example
I'd like to see an express example using the latest and greatest fable.
Actually we want to create a samples-node repo with express and other server-side samples. However, I haven't used Fable wit express myself that much. Maybe someone else has more experience? @et1975?
That sounds great.
It is currently rather confusing to get dotnet fable webpack to output some javascript.
App.fsx:
#r "C:\temp\FableInterop\packages\Fable.Core\lib\netstandard1.6\Fable.Core.dll"
#r "C:\temp\FableInterop\packages\Fable.Import.Express\lib\netstandard1.6\Fable.Import.Express.dll"
open System
open Fable.Core
open Fable.Core.JsInterop
open Fable.Import
let app = express.Invoke()
app.get
(U2.Case1 "/",
fun (req:express.Request) (res:express.Response) _ ->
res.send(sprintf "Hello") |> box)
|> ignore
// Get PORT environment variable or use default
let port =
match unbox Node.``process``.env?PORT with
| Some x -> x | None -> 8080
// Start the server on the port
app.listen(port, unbox (fun () ->
printfn "Server started: http://localhost:%i/" port))
|> ignore
[0] ./FableInterop.fsproj 0 bytes {0} [built] [2 warnings] [4 errors]
WARNING in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(1,0): (1,79) warning FSHARP: 'C: emp\FableInterop\packages\Fable.Core\lib
etstandard1.6\Fable.Core.dll' is not a valid assembly name
WARNING in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(2,0): (2,99) warning FSHARP: 'C: emp\FableInterop\packages\Fable.Import.Express\lib
etstandard1.6\Fable.Import.Express.dll' is not a valid assembly name
ERROR in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(11,10): (11,17) error FSHARP: The value, namespace, type or module 'express' is not defined. Maybe you want one of the following:
exp
ERROR in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(13,0): (13,7) error FSHARP: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program poi
nt to constrain the type of the object. This may allow the lookup to be resolved.
ERROR in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(21,19): (21,30) error FSHARP: The value, constructor, namespace or type 'process' is not defined. Maybe you want one of the following:
Process
ERROR in ./FableInterop.fsproj
C:\temp\FableInterop\App.fsx(25,0): (25,10) error FSHARP: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program po
int to constrain the type of the object. This may allow the lookup to be resolved.
Closing server...
I'm also not really a seasoned fsharp dev, so I might just be missing a very basic thing here.
Can you please try adding @ in front of the path strings?
#r @"C:\temp\FableInterop\packages\Fable.Core\lib\netstandard1.6\Fable.Core.dll"
#r @"C:\temp\FableInterop\packages\Fable.Import.Express\lib\netstandard1.6\Fable.Import.Express.dll"
That makes them verbatim strings, meaning \t won't be interpreted as a tab character.
No luck
Ok, we'll try to add a Express sample that works with latest Fable :) Maybe @fable-compiler/documentation, @MangelMaxime can help with that? 😉
I've started porting our elmish-ws sample to latest Fable, it uses Express for websockets, will try to wrap it up soon.