How to use Node.js in asp.net MVC using Visual Studio?

0

I currently have a project created asp.net MVC in C # and I wanted to add code from Node.js.

Download the Node.js from the package nuget and install it by creating a .bin folder containing node.cmd in the project

I have the following code in the view that has the cshtml extension and wanted to start testing the node.js code:

<!DOCTYPE html>

<html>
<head runat="server">
    <meta name="viewport" content="width=device-width" />
    <title>Login</title>
    <script src="../../Scripts/jquery-3.1.1.min.js"></script>
    <script src="../../Scripts/bootstrap.min.js"></script>
    <link href="../../Content/bootstrap.min.css" rel="stylesheet" />
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

    <script>
        var http = require('http');

        http.createServer(function (req, res) {
            res.writeHead(200, { 'Content-Type': 'text/plain' });
            res.end('Hello World!');
        }).listen(8080);

    </script>
</head>
<body>
//codigo de razor , C# html, etc
</body>
</html>

I wanted to try the code, but it does not work. The truth is that I have not worked with Node.js, and that's why I wanted to start learning and incorporate it into my already created project. What should I do to make Node.js work in my asp.net MVC project in Visual Studio? Greetings

    
asked by Danilo 10.09.2018 в 20:36
source

1 answer

1

Nodejs is not executed in a .html page but in a js file and you have to have nodejs installed and run through cmd windows or terminal linux or macOS example

//index.js
var http = require('http');
http.createServer(function (req, res) {
        res.writeHead(200, { 'Content-Type': 'text/plain' });
        res.end('Hello World!');
    }).listen(8080);

and in the terminal enter the path where the index.js file is located and run node index.js

    
answered by 12.09.2018 в 08:37