无法访问linux机器中的端口,但能够使用nodejs& amp;角js

时间:2018-03-02 20:47:05

标签: node.js linux angular child-process

运行节点& angularjs通过提供监听端口在我的窗口上投影,它正在运行。 但同时在Linux机器端口上运行相同的代码是不可访问的。 我试过命令, node node.js node node.js --port 8952 --host 0.0.0.0 --disableHostCheck true  但它对Linux VM无效

请建议您进行全面更改。谢谢..!!

Angular.js

<body ng-app="myApp">
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<link rel="stylesheet" type="angular/css">
<div style="text-align: center">
<h1 style="color: cornflowerblue"><b>Angular MVN ArchType</b></h1></div>

<div ng-controller="myCtrl">
    <br>
    <div style="margin-left: 40%">
        <input type="text" ng-model="par1">
        <button class="button" ng-click="myFunc()"><b>GET</b></button>
        <br>
        <br>
    </div>
    <div>
        <div style="margin-left: 30%">
            <textarea style="width: 500px;height: 500px">{{data}}</textarea>
        </div>
    </div>

</div>


<script>
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function ($scope, $http) {

        $scope.myFunc = function () {

            $http({
                method: 'GET',
                url: './fetch/',
                params: {"id": $scope.par1},
            })
                .success(function (data, status) {
                    console.log(data);
                    $scope.data = data;
                })
                .error(function (data, status) {
                    alert("Error in scripting angular");
                });

        };
    });    
</script>
</body>

Node.js的

var express = require('express'),
app = express();

var bodyParser = require("body-parser");
app.use(bodyParser.json()); // support json encoded bodies
app.use(bodyParser.urlencoded({ extended: true }));
const child_process = require('child_process');


app.get('/fetch', function(req,res){
    console.error('hello inside node ');

    var id = req.query.id;


    console.log("In progressss...........");

    child_process.exec('echo hello ' + id, function (error, stdout, stderr) {


        res.send(stdout.toString());
    });

});
app.get('/', function(request, response){
    response.sendfile('index.html');
});

app.listen(4378);
console.log('Rest Demo Listening on port 4378');

0 个答案:

没有答案