[backend][nodejs] Use express framework instead of http module
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
"main": "lib/app.js",
|
||||
"scripts": {
|
||||
"test": "ts-mocha -p tsconfig.json src/**/*.spec.ts",
|
||||
"start": "tsc && node lib/app.js build:live",
|
||||
"start": "tsc && node lib/app.js",
|
||||
"build": "tsc -p .",
|
||||
"build:live": "nodemon --watch 'src/**/*.ts' --exec \"ts-node\" src/app.ts"
|
||||
},
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import {IncomingMessage, ServerResponse} from "http";
|
||||
|
||||
const http = require('http');
|
||||
import express from 'express';
|
||||
const randomDecision = require("./random-decision")
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
|
||||
const server = http.createServer((request: IncomingMessage, response: ServerResponse) => {
|
||||
response.statusCode = 200;
|
||||
response.setHeader('Content-Type', 'text/plain');
|
||||
response.end(randomDecision.getRandomChoice().toString());
|
||||
});
|
||||
app.get('/', ((req, response) => {
|
||||
response.send(randomDecision.getRandomChoice());
|
||||
}));
|
||||
|
||||
server.listen(port, () => {
|
||||
console.log(`Server listening on port ${port}`)
|
||||
app.listen(port, () => {
|
||||
return console.log(`Server is listening on port ${port}`);
|
||||
});
|
||||
Reference in New Issue
Block a user