express-csv provides response csv easily to express.
_____ ____ ______ __ | ____|_ ___ __ _ __ ___ ___ ___ / ___/ ___\ \ / / | _| \ \/ / '_ \| '__/ _ \/ __/ __| | | \___ \\ \ / / | |___ > <| |_) | | | __/\__ \__ \ | |___ ___) |\ V / |_____/_/\_\ .__/|_| \___||___/___/ \____|____/ \_/ |_|
Express CSV provides response CSV easily to Express.
$ sbt clean publish-local
Before running the tests the first time, you must ensure the npm packages are installed:
$ npm install
Then you can run the tests:
$ sbt test
import io.scalajs.npm.express._
import io.scalajs.npm.express.csv._
import scalajs.js
// load the Express modules
val app = Express()
ExpressCSV
app.get("/", { (_: Request, res: Response with CSVResponse) =>
res.csv(
js.Array(
js.Array("a", "b", "c"),
js.Array("d", "e", "f")
))
})
.listen(8080)
import io.scalajs.nodejs.http._
import io.scalajs.npm.express.csv._
Http.get("http://localhost:8080/", { response: ServerResponse =>
response.onData { chunk =>
val data = chunk.toString().split('\n').map(_.trim).mkString("|")
println(data) // "a","b","c"|"d","e","f"
}
})
To add the ExpressCSV
binding to your project, add the following to your build.sbt:
libraryDependencies += "io.scalajs.npm" %%% "express-csv" % "0.5.0"
Optionally, you may add the Sonatype Repository resolver:
resolvers += Resolver.sonatypeRepo("releases")