I am trying to write a Express server in typescript (basically following the last chapter of the book “introducing rescript”)
I wrote this code
open Express
let app = express()
app -> use(jsonMiddleware())
app -> get("/", (_, response) => {
open NodeJs
response->sendFile(Path.join([Global.dirname, "index.html"]))->ignore
})
let _ = app->listen(4000, _=> {
Js.Console.log("server is running on 4000")})
my bsconfig.json looks like
{
"name": "example1",
"version": "0.1.0",
"sources": {
"dir" : "src",
"subdirs" : true
},
"package-specs": {
"module": "es6",
"in-source": true
},
"suffix": ".bs.js",
"jsx": { "version": 4, "mode": "classic" },
"bs-dependencies": [
"@rescript/react",
"rescript-express",
"rescript-webapi",
"rescript-nodejs"],
"reason": {"react-jsx": 3}
}
and package.json like
{
"name": "example1",
"version": "0.1.0",
"type": "module",
"scripts": {
"clean": "rescript clean -with-deps",
"build": "rescript build && webpack",
"watch": "rescript build -w"
},
"keywords": [
"ReScript"
],
"author": "",
"license": "MIT",
"devDependencies": {
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.3",
"html-webpack-plugin": "^5.5.0",
"rescript": "^10.0.1",
"style-loader": "^3.3.1",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1",
"webpack-html-plugin": "^0.1.1"
},
"dependencies": {
"@rescript/react": "^0.11.0",
"rescript-express": "^0.4.1",
"rescript-nodejs": "^14.3.1",
"rescript-webapi": "^0.7.0"
}
}
when I say node src/Server.bs.js
I get error
╰─$ node src/Server.bs.js
file:///Users/foo/code/Rescript/example1/src/Server.bs.js:6
var app = Express();
^
TypeError: Express is not a function
at file:///Users/foo/code/Rescript/example1/src/Server.bs.js:6:11
at ModuleJob.run (node:internal/modules/esm/module_job:193:25)
Node.js v19.6.1