Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Running an angular app using node js

I have a html page and a serviceController.js, I need to automatically run the app through node js. Sorry for the naive question but am unable to run it. My serviceController.js looks like this :

var app = angular.module("app", []);
app.controller('serviceController', ['$scope', '$interval','$http',  function($scope, $interval, $http) 
{  $scope.service1 = {//and so on..
}

I was following an example and I have tried the following: created a package.json :

{  "name": "express-html", 
 "version": "0.0.1", 
 "dependencies": {    
"express": "^4.11.0"  
}}

My server.js looks like this :

var express = require("express");
var app     = express();
var path    = require("path");
app.get('/',function(req,res){  
   res.sendFile(path.join(__dirname+'/index.html')); 
});

app.listen(3000);
console.log("Running at Port 3000");

But, when I try starting the application from terminal using: node server.js. I get the following error :

(function (exports, require, module, __filename, __dirname) 
{ var app = angular.module("app", []);                             
^ReferenceError: angular is not defined    at Object.<anonymous> (/Users/dem/Desktop/frontend/task3/serviceController.js:1:81)    
at Module._compile (module.js:570:32)    
at Object.Module._extensions..js (module.js:579:10)    
at Module.load (module.js:487:32)    
at tryModuleLoad (module.js:446:12)    
at Function.Module._load (module.js:438:3)    
at Module.require (module.js:497:17)    
at require (internal/module.js:20:19)    
at Object.<anonymous> (/Users/dem/Desktop/frontend/task3/server.js:5:19)    
at Module._compile (module.js:570:32)

Please guide!

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

app.use("/", express.static(__dirname)); Use this in place of

res.sendFile(path.join(__dirname+'/index.html'));

about 4 years ago · Santiago Trujillo Relatório

0

Update server file to serve a static directory like app.use(express.static('dirPath')) For more detail visit Serving static files in Express

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda