How do I create a TypeScript project for NodeJS in Visual Studio 2022 (non-code)

I want to develop a nodeJS script in a Visual Studio 2022 (not Visual Studio Code) project.
I have a ASP.NET Core C# project.
In that project, i have a folder TypeScript.
In the typescript i have several subfolders, where I develop TypeScript scripts, that are transpiled to /wwwroot/ts/<foldername>/outputname.js

Now, appart from all these JSs for the browser, I want to create one JS for nodeJS (a console test application).

I really struggle to figure out how to configure this in tsconfig.json

I have the following main.ts file:

import * as http from "http";
import * as https from "https";

const EXIT_SUCCESS = 0;
const EXIT_FAILURE = 1;


// Define the main function, and make it async
async function main(args:string[]): Promise<number>
{
    if (args.length === 0)
    {
        console.log("No arguments provides.");
    } 
    else
    {
        // Log all arguments using a for loop
        for (let i = 0; i < args.length; i++)
        {
            console.log(`Argument ${i + 1}: ${args[i]}`);
        }
    }

    // Simulate async operation, like a delay
    await new Promise(function (resolve) { setTimeout(resolve, 1000); });
    console.log("Finished ! ");
    return EXIT_SUCCESS;
}



(function ()
{
    // process.argv[0]: This represents the name or the path to the Node.js executable
    // process.argv[1]: file path of the script file being executed.

    // Process command-line arguments (starts from index 2, 
    // since first two args are 'node' and the script path)
    const args = process.argv.slice(2);

    function handleSuccess(exitCode: number)
    {
        process.exit(exitCode);
    }

    function handleError(err: any)
    {
        if (err instanceof Error)
        {
            console.error("An error occurred:", err);
            console.error("ErrorType:", err.name);
            console.error("ErrorMessage:", err.message);
            console.error("StackTrace:", err.stack);
        }
        else
            console.error("An error occurred:", err);

        process.exit(EXIT_FAILURE);
    }

    // Call the async main function
    main(args).then(handleSuccess).catch(handleError);
})();

And then I have this tsconfig.json

{
  "compileOnSave": true,

  "compilerOptions": {
    "target": "ES2015", //"target": "es5",
    //"module": "amd", // define, export, like playground
    // "module": "commonjs", // require
    "module": "Node16",
    "types": [ "node" ],

    // "module": "commonjs", // just like typescript
    // "module": "system", // System.register
    // "module": "umd", // factory, require, exports
    // "module": "esnext", // like typescript
    // "module": "none", // Object.defineProperty, require
    // "module": "commonjs",
    "lib": [
      "ES2020"
    ],

    "noImplicitAny": true,
    "noEmitOnError": true,
    "removeComments": true,
    "sourceMap": false,
    "outDir": "../../wwwroot/nodeapp",
    "rootDir": "./",
    "allowUnreachableCode": true,

    "moduleResolution": "node" // Resolve modules using Node.js rules

    //,"alwaysStrict ": true,
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ],

  "include": [
    "**/*" ]

}

Now normally, i have for the browser:

"lib": [
  "DOM",
  "ES2016",
  "ES2015.Promise",
  "ES2015.Proxy"
],

But for the NodeJS, I thought I could do something like

"lib": [
  "node",
  "ES2020"
],

and finished, but that doesn’t work.
It won’t recognize node as a valid lib.

The only way I’ve found i can make this work is to put node.d.ts into my folder.
And while it now finds process, it won’t recognize console, although node.d.ts defines it in global. I presume this is because it does not recognize global as the global namespace. Instead searching in window or whatever.

How can I fix this, so I won’t have to write global.console ?
Is this typescript nuget for Visual Studio really so stupid that it does not recognize that I want to build a nodeJS app this time, and there also is no way to tell it that ?

I’d really hate to have to add anything with npm manually, as this breaks the automated build process (continuous integration system).

Ah, I got this myself.
My node.d.ts was incomplete.

First get all required d.ts files via

git clone https://github.com/DefinitelyTyped/DefinitelyTyped
git clone https://github.com/nodejs/undici

Now copy all types from DefinitelyTyped/types/node/v20
to the a new folder nodev20 in your root project directory.
Then, rename nodev20/index.d.ds to nodev20/node.d.ds

Now, copy all files from /undici/undici/types to new folder nodev20/undici-types

Then, in the undici folder, where required, add node via reference to the parent directory

/// <reference types="../node" />

Now in globals.d.ts of nodev20 folder, replace imports to undici with
import * as Undici from "./undici-types/index";
and then search-and-replace import("undici-types") with Undici. .

Done, now the nodeJS project transpiles, and you have full intellisense support for NodeJS in VS2022 without requiring npm.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

How do I create a TypeScript project for NodeJS in Visual Studio 2022 (non-code)

I want to develop a nodeJS script in a Visual Studio 2022 (not Visual Studio Code) project.
I have a ASP.NET Core C# project.
In that project, i have a folder TypeScript.
In the typescript i have several subfolders, where I develop TypeScript scripts, that are transpiled to /wwwroot/ts/<foldername>/outputname.js

Now, appart from all these JSs for the browser, I want to create one JS for nodeJS (a console test application).

I really struggle to figure out how to configure this in tsconfig.json

I have the following main.ts file:

import * as http from "http";
import * as https from "https";

const EXIT_SUCCESS = 0;
const EXIT_FAILURE = 1;


// Define the main function, and make it async
async function main(args:string[]): Promise<number>
{
    if (args.length === 0)
    {
        console.log("No arguments provides.");
    } 
    else
    {
        // Log all arguments using a for loop
        for (let i = 0; i < args.length; i++)
        {
            console.log(`Argument ${i + 1}: ${args[i]}`);
        }
    }

    // Simulate async operation, like a delay
    await new Promise(function (resolve) { setTimeout(resolve, 1000); });
    console.log("Finished ! ");
    return EXIT_SUCCESS;
}



(function ()
{
    // process.argv[0]: This represents the name or the path to the Node.js executable
    // process.argv[1]: file path of the script file being executed.

    // Process command-line arguments (starts from index 2, 
    // since first two args are 'node' and the script path)
    const args = process.argv.slice(2);

    function handleSuccess(exitCode: number)
    {
        process.exit(exitCode);
    }

    function handleError(err: any)
    {
        if (err instanceof Error)
        {
            console.error("An error occurred:", err);
            console.error("ErrorType:", err.name);
            console.error("ErrorMessage:", err.message);
            console.error("StackTrace:", err.stack);
        }
        else
            console.error("An error occurred:", err);

        process.exit(EXIT_FAILURE);
    }

    // Call the async main function
    main(args).then(handleSuccess).catch(handleError);
})();

And then I have this tsconfig.json

{
  "compileOnSave": true,

  "compilerOptions": {
    "target": "ES2015", //"target": "es5",
    //"module": "amd", // define, export, like playground
    // "module": "commonjs", // require
    "module": "Node16",
    "types": [ "node" ],

    // "module": "commonjs", // just like typescript
    // "module": "system", // System.register
    // "module": "umd", // factory, require, exports
    // "module": "esnext", // like typescript
    // "module": "none", // Object.defineProperty, require
    // "module": "commonjs",
    "lib": [
      "ES2020"
    ],

    "noImplicitAny": true,
    "noEmitOnError": true,
    "removeComments": true,
    "sourceMap": false,
    "outDir": "../../wwwroot/nodeapp",
    "rootDir": "./",
    "allowUnreachableCode": true,

    "moduleResolution": "node" // Resolve modules using Node.js rules

    //,"alwaysStrict ": true,
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ],

  "include": [
    "**/*" ]

}

Now normally, i have for the browser:

"lib": [
  "DOM",
  "ES2016",
  "ES2015.Promise",
  "ES2015.Proxy"
],

But for the NodeJS, I thought I could do something like

"lib": [
  "node",
  "ES2020"
],

and finished, but that doesn’t work.
It won’t recognize node as a valid lib.

The only way I’ve found i can make this work is to put node.d.ts into my folder.
And while it now finds process, it won’t recognize console, although node.d.ts defines it in global. I presume this is because it does not recognize global as the global namespace. Instead searching in window or whatever.

How can I fix this, so I won’t have to write global.console ?
Is this typescript nuget for Visual Studio really so stupid that it does not recognize that I want to build a nodeJS app this time, and there also is no way to tell it that ?

I’d really hate to have to add anything with npm manually, as this breaks the automated build process (continuous integration system).

Ah, I got this myself.
My node.d.ts was incomplete.

First get all required d.ts files via

git clone https://github.com/DefinitelyTyped/DefinitelyTyped
git clone https://github.com/nodejs/undici

Now copy all types from DefinitelyTyped/types/node/v20
to the a new folder nodev20 in your root project directory.
Then, rename nodev20/index.d.ds to nodev20/node.d.ds

Now, copy all files from /undici/undici/types to new folder nodev20/undici-types

Then, in the undici folder, where required, add node via reference to the parent directory

/// <reference types="../node" />

Now in globals.d.ts of nodev20 folder, replace imports to undici with
import * as Undici from "./undici-types/index";
and then search-and-replace import("undici-types") with Undici. .

Done, now the nodeJS project transpiles, and you have full intellisense support for NodeJS in VS2022 without requiring npm.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật