Switched over to ExpressJS Hosting

++ CS212-Projects file copy
++ public folder
++ node stuff
This commit is contained in:
Charles Descamps 2023-04-10 15:14:27 -07:00
parent a7acb7acc8
commit 60087976ca
473 changed files with 66395 additions and 0 deletions

27
server.js Normal file
View file

@ -0,0 +1,27 @@
const express = require('express')
const logger = require('morgan')
const path = require('path')
const server = express()
server.use(express.urlencoded({'extended': true}))
server.use(logger('dev'))
// Routes
server.get('/do_a_random', (req, res) => {
res.send(`Your number is: ${Math.floor(Math.random() * 100) + 1}`)
})
// Setup static page serving for all the pages in "public"
const publicServedFilesPath = path.join(__dirname, 'public')
server.use(express.static(publicServedFilesPath))
// The server uses port 80 by default unless you start it with the extra
// command line argument 'local' like this:
// node server.js local
let port = 80
if (process.argv[2] === 'local') {
port = 8080
}
server.listen(port, () => console.log('Ready on localhost!'))