bootstrap js projects
This commit is contained in:
2
express-js/.gitignore
vendored
Normal file
2
express-js/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
node_modules/
|
||||
build/
|
||||
1180
express-js/package-lock.json
generated
Normal file
1180
express-js/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
express-js/package.json
Normal file
25
express-js/package.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "money-transfer",
|
||||
"version": "1.0.0",
|
||||
"main": "server.ts",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"build": "tsc",
|
||||
"dev": "node ./build/server.js",
|
||||
"start": "tsc && npm run dev"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"description": "",
|
||||
"devDependencies": {
|
||||
"@types/cors": "^2.8.19",
|
||||
"@types/express": "^5.0.3",
|
||||
"@types/node": "^24.0.10",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"cors": "^2.8.5",
|
||||
"express": "^5.1.0"
|
||||
}
|
||||
}
|
||||
18
express-js/server.ts
Normal file
18
express-js/server.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import express, { Application } from "express";
|
||||
import Server from "./src/index";
|
||||
|
||||
const app: Application = express();
|
||||
const server: Server = new Server(app);
|
||||
const PORT: number = process.env.PORT ? parseInt(process.env.PORT, 10) : 8080;
|
||||
|
||||
app
|
||||
.listen(PORT, "localhost", function () {
|
||||
console.log(`Server is running on port ${PORT}.`);
|
||||
})
|
||||
.on("error", (err: any) => {
|
||||
if (err.code === "EADDRINUSE") {
|
||||
console.log("Error: address already in use");
|
||||
} else {
|
||||
console.log(err);
|
||||
}
|
||||
});
|
||||
18
express-js/src/index.ts
Normal file
18
express-js/src/index.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import express, { Application } from "express";
|
||||
import cors, { CorsOptions } from "cors";
|
||||
|
||||
export default class Server {
|
||||
constructor(app: Application) {
|
||||
this.config(app);
|
||||
}
|
||||
|
||||
private config(app: Application): void {
|
||||
const corsOptions: CorsOptions = {
|
||||
origin: "http://localhost:8081"
|
||||
};
|
||||
|
||||
app.use(cors(corsOptions));
|
||||
app.use(express.json());
|
||||
app.use(express.urlencoded({ extended: true }));
|
||||
}
|
||||
}
|
||||
25
express-js/tsconfig.json
Normal file
25
express-js/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Language and Environment */
|
||||
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
||||
"experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
"emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "commonjs", /* Specify what module code is generated. */
|
||||
"resolveJsonModule": true, /* Enable importing .json files. */
|
||||
|
||||
/* Emit */
|
||||
"outDir": "./build", /* Specify an output folder for all emitted files. */
|
||||
|
||||
/* Interop Constraints */
|
||||
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
||||
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
|
||||
/* Completeness */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user