角度不是用node . js定义的

时间:2021-08-15 16:56:12

I'm fairly new to Angular and NodeJS and trying to run a sample website.

我对有棱角的和NodeJS都很陌生,我尝试着运营一个示例网站。

From what I understood, to run it I simply need to execute "node app.js".

据我所知,要运行它,我只需执行“节点app.js”。

However, I get the following error:

但是,我有以下错误:

C:\app\app.js:3
angular
^

ReferenceError: angular is not defined
at Object.<anonymous> (C:\app\app.js:3:1)
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.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3

My app.js looks like this:

我的app。js是这样的:

'use strict';

angular
  .module('apmportal', [
    'ngCookies',
    'ngResource'
])

The project's structure is:

项目的结构是:

角度不是用node . js定义的

Here is the index.html:

这是index . html:

  <!-- build:js scripts/vendor.js -->
  <!-- bower:js -->
  <script src="bower_components/jquery/dist/jquery.js"></script>
  <script src="bower_components/angular/angular.js"></script>
  <script src="bower_components/angular-resource/angular-resource.js">

App folder structure:

应用程序文件夹结构:

角度不是用node . js定义的

I should mention that node is installed and I've also ran bower install to install all dependencies. Clearly I'm missing something here but I just cant figure out what.

我应该提到已经安装了node,我还运行了bower install来安装所有依赖项。很明显,我漏掉了一些东西,但我就是搞不清是什么。

Appreciate your help.

感谢你的帮助。

1 个解决方案

#1


3  

You cannot run node app.js because app.js is your front-end file. create server.js outside in your project structure and serve app/index.html from that(you should have index.html inside app folder). then run node server.js

您不能运行node app.js,因为app.js是您的前端文件。创建服务器。在你的项目结构之外,提供应用/索引。从中得到html(应该有索引。html应用程序文件夹内)。然后运行节点server.js

If you don't have idea about set up backend check this project structure

如果您不知道如何设置后端,请检查这个项目结构

Project Structure

项目结构

In my case I have server code in app.js so it would be node app.js in my case

在我的例子中,我在app.js中有服务器代码,所以在我的例子中是node app.js

#1


3  

You cannot run node app.js because app.js is your front-end file. create server.js outside in your project structure and serve app/index.html from that(you should have index.html inside app folder). then run node server.js

您不能运行node app.js,因为app.js是您的前端文件。创建服务器。在你的项目结构之外,提供应用/索引。从中得到html(应该有索引。html应用程序文件夹内)。然后运行节点server.js

If you don't have idea about set up backend check this project structure

如果您不知道如何设置后端,请检查这个项目结构

Project Structure

项目结构

In my case I have server code in app.js so it would be node app.js in my case

在我的例子中,我在app.js中有服务器代码,所以在我的例子中是node app.js