Server Side Dependency Imports
Video Lecture
Description
This is predominantly a Three.js course, but we are writing the code using TypeScript, and we are also hosting the code though a NodeJS server. So we will also learn about those two things as well and how to merge these three technologies so that they work effortlessly together.
First, let us get the server side code running first so that it at least serves some code, and then move onto solving the problems of the client in the next video.
See Video for all NPM commands and the order of execution.
./src/server/server.ts
import express from 'express'
import path from 'path'
import http from 'http'
const port: number = 3000
class App {
private server: http.Server
private port: number
constructor(port: number) {
this.port = port
const app = express()
app.use(express.static(path.join(__dirname, '../client')))
this.server = new http.Server(app)
}
public Start() {
this.server.listen(this.port, () => {
console.log(`Server listening on port ${this.port}.`)
})
}
}
new App(port).Start()
At the end of this section, all imports for the server.ts
will be properly linked, and we can then compile and view the project so far.
tsc -p ./src/server
node ./dist/server/server.js
Open a browser and visit http://127.0.0.1:3000/