Node.js + TypeScript2023/09/13 |
|
Node.js पर TypeScript वातावरण कॉन्फ़िगर करें।
|
|
| [1] | |
| [2] | एक सामान्य उपयोगकर्ता के रूप में TypeScript के साथ एक परीक्षण प्रोजेक्ट बनाएं। |
|
# package.json जनरेट करें ubuntu@dlp:~/testproject$ npm init -y
Wrote to /home/ubuntu/testproject/package.json:
{
"name": "testproject",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
# TypeScript इंस्टॉल करें ubuntu@dlp:~/testproject$ npm install typescript ts-node added 19 packages, and audited 20 packages in 6s found 0 vulnerabilities # Node.js प्रकार की घोषणा फ़ाइल स्थापित करें ubuntu@dlp:~/testproject$ npm install @types/node up to date, audited 20 packages in 529ms found 0 vulnerabilities # tsconfig.json उत्पन्न करें ubuntu@dlp:~/testproject$ npx tsc --init --module commonjs Created a new tsconfig.json with: target: es2016 module: commonjs strict: true esModuleInterop: true skipLibCheck: true forceConsistentCasingInFileNames: true You can learn more at https://aka.ms/tsconfigubuntu@dlp:~/testproject$ grep -v -E "^ */|^$" tsconfig.json
{
"compilerOptions": {
"target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"module": "commonjs", /* Specify what module code is generated. */
"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. */
"strict": true, /* Enable all strict type-checking options. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
# एक परीक्षण ऐप बनाएं ubuntu@dlp:~/testproject$ mkdir src
ubuntu@dlp:~/testproject$
vi src/test-app.ts
import * as http from "http";
import * as os from 'os';
const hostname = os.hostname();
const port = 3000;
const server = http.createServer((req, res) =>
{
res.write("Hello TypeScript World on Node.js!\n");
res.end();
}
);
server.listen(port);
console.log(`http://${hostname}:${port}`);
./node_modules/.bin/ts-node src/test-app.ts http://dlp.srv.world:3000 |
| किसी भी क्लाइंट कंप्यूटर से ऊपर कंसोल पर दिखाए गए यूआरएल तक पहुंच, और फिर यदि निम्नलिखित ऐप दिखाया जाता है तो यह ठीक है। |
|
| Sponsored Link |
|
|