node Express 创建一个web应用

环境安装的node版本是最新的,下个月会发布4.0,把io.js合并进来。

[[email protected] myExpressApp]$ node --version
v0.12.7

npm和node版本中的npm版本更新是不同布的,我们要经常更新npm包,

[[email protected] ~]$ npm install --g npm
/home/doctor/opt/node/bin/npm -> /home/doctor/opt/node/lib/node_modules/npm/bin/npm-cli.js
[email protected] /home/doctor/opt/node/lib/node_modules/npm
[[email protected] ~]$

Express是hode中非常出名的重要web框架。我们可以用Express Generator工具生成一个Express应用。

安装Express Generator工具:

[[email protected] ~]$ npm install -g express-generator
/home/doctor/opt/node/bin/express -> /home/doctor/opt/node/lib/node_modules/express-generator/bin/express
[email protected] /home/doctor/opt/node/lib/node_modules/express-generator
├── [email protected]
├── [email protected] ([email protected])
└── [email protected] ([email protected])
[[email protected] ~]$

下面我们创建一个Express应用:

[[email protected] WebstormProjects]$ express myExpressApp

   create : myExpressApp
   create : myExpressApp/package.json
   create : myExpressApp/app.js
   create : myExpressApp/public
   create : myExpressApp/routes
   create : myExpressApp/routes/index.js
   create : myExpressApp/routes/users.js
   create : myExpressApp/views
   create : myExpressApp/views/index.jade
   create : myExpressApp/views/layout.jade
   create : myExpressApp/views/error.jade
   create : myExpressApp/bin
   create : myExpressApp/bin/www
   create : myExpressApp/public/javascripts
   create : myExpressApp/public/images
   create : myExpressApp/public/stylesheets
   create : myExpressApp/public/stylesheets/style.css

   install dependencies:
     $ cd myExpressApp && npm install

   run the app:
     $ DEBUG=myExpressApp:* npm start

根据提示:

安装应用依赖包:

[[email protected] WebstormProjects]$ cd myExpressApp/
[[email protected] myExpressApp]$ npm install
[email protected] node_modules/cookie-parser
├── [email protected]
└── [email protected]

[email protected] node_modules/debug
└── [email protected]

[email protected] node_modules/serve-favicon
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]

[email protected] node_modules/morgan
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected] ([email protected])

[email protected] node_modules/body-parser
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
└── [email protected] ([email protected], [email protected])

[email protected] node_modules/express
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected])
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])

[email protected] node_modules/jade
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected])
└── [email protected] ([email protected], [email protected])
[[email protected] myExpressApp]$

一个基本的Express应用建好了,运行一下:

[[email protected] myExpressApp]$ DEBUG=myExpressApp:* npm start

> [email protected] start /home/doctor/WebstormProjects/myExpressApp
> node ./bin/www

  myExpressApp:server Listening on port 3000 +0ms

或直接:

npm start

如果让编辑器代码提示的更好,需要安装微软的 TypeScript Definition Manager (TSD)

npm install -g tsd

现在我们可以用tsd下载node和express的定义文件:

[[email protected] myExpressApp]$ tsd query node

 - node / node
[[email protected] myExpressApp]$ tsd query node --action install

 - node / node    

>> running install..

>> written 1 file:

    - node/node.d.ts
[[email protected] myExpressApp]$ tsd query express

 - express / express
[[email protected] myExpressApp]$ tsd query express --action install

 - express / express    

>> running install..

>> written 1 file:

    - express/express.d.ts
[[email protected] myExpressApp]$

写代码的离不开调式工具,它是一个最真诚的朋友,伴随你一生。

node express我用的是微软开源的vs code(不要喷微软,起码人家已经开始为开源做贡献了,不像有些公司拿了开源的就封闭了),要让vs code能调试node express ,我们需要安装mono。

我还是懒得下载rar包,解压,配置环境了,dnf在线安装吧。

安装文档在:http://www.mono-project.com/docs/getting-started/install/linux/#usage

重要的事情重复一下,重要的事情重复一下:

CentOS, Fedora, and derivatives

Add the Mono Project GPG signing key and the package repository in a root shell with:

rpm --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"
yum-config-manager --add-repo http://download.mono-project.com/repo/centos/

Run a package upgrade to upgrade existing packages to the latest available. Then install Mono as described in the Usage section.

Users of CentOS or RHEL (or similar distributions) may need to add the EPEL
repository
 to their system to satisfy all dependencies.

[[email protected] ~]# rpm --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"

[[email protected] ~]#
[[email protected] ~]# yum-config-manager --add-repo http://download.mono-project.com/repo/centos/

Yum-utils package has been deprecated, use dnf instead.
See 'man yum2dnf' for more information.

Repository pgdg94 is listed more than once in the configuration
Repository pgdg94-source is listed more than once in the configuration
adding repo from: http://download.mono-project.com/repo/centos/

[download.mono-project.com_repo_centos_]
name=added from: http://download.mono-project.com/repo/centos/
baseurl=http://download.mono-project.com/repo/centos/
enabled=1

[[email protected] ~]# dnf install mono

设置一个断点:14行处:

打开调试视图,左侧竖着放的菜单最后一个:

断点处程序停止了。上面多出了一个可以控制调试流程的小工具。

版权声明:本文为博主原创文章,未经博主允许不得转载[http://blog.csdn.net/doctor_who2004]。

时间: 2024-10-15 04:51:55

node Express 创建一个web应用的相关文章

Node.js学习笔记(6)——使用Express创建一个工程

前提是搭建好了环境,node,npm,express:(推荐全局安装) 开始用express创建一个基础工程: express –t ejs microblog 进入文件夹之后 npm-install(自动安装好要用的依赖) 这个时候,用浏览器访问localhost:3000,就可以出来一个欢迎界面了,这里简单说下原理:当你在浏览器输入这个地址砸下回车的瞬间,node搭建的一个网站后台程序开始工作,在app.js这个文件里面,有app.get(‘/’, routes.index);这一句话的作用

eclipes创建一个web项目web.xml不能自动更新的原因(web.xml和@WebServlet的作用)

在eclipse中创建一个Web项目的时候,虽然有web.xml生成,但是再添加Servlet类文件的时候总是看不见web.xml的更新,所以异常的郁闷!上网查了查,原来我们在创建Web项目的时候,会弹出一个对话框,“Dynamic web module version”这个选项默认成了3.0,按照老规范,应该是在eclipse的WebContent \ WEB-INF \ 目录下创建web.xml的.而新规范是可以不用web.xml的,如tomcat 7.0就支持新规范,这样相关的servle

使用eclipse插件创建一个web project

使用eclipse插件创建一个web project 首先创建一个Maven的Project如下图 我们勾选上Create a simple project (不使用骨架) 这里的Packing 选择 war的形式 由于packing是war包,那么下面也就多出了webapp的目录 由于我们的项目要使用eclipse发布到tomcat下面,这里我们需要先把项目转成dynamic web project 在我们的项目上点击右键,选择properties 并找到 Project Facets ,并点

使用CXF+spring+restful创建一个web的接口项目

此文为http://blog.csdn.net/zxnlmj/article/details/28880303的下文,在其基础上添加restful功能 1.添加restful的所需jar包 jsr311-api-1.0.jar CXF与JAX-RS版本对应问题,参考自:http://bioubiou.iteye.com/blog/1866871 CXF支持REST风格的Web服务:JAX-RS2.0(JSR-339)和JAX-RS1.1(JSR-311)的Java API. CXF2.7.0支持

使用CXF+spring创建一个web的接口项目

一.web project整合spring 1.1.打开Myeclipse,建立web project(eclipse为dynamic web project),使用J2EE5.0. 1.2.添加Srping的基本jar包(无需事务等) org.springframework.beans-3.1.1.RELEASE.jar commons-logging.jar org.springframework.aop-3.1.1.RELEASE.jar org.springframework.asm-3

IntelliJ IDEA 中配置Maven以及创建一个Web项目

IntelliJ IDEA 中配置Maven Step.1 File-Settings Step.2 使用Maven创建一个Web项目 Step.1 File-New-Project Step.2

自己动手创建一个Web Server(非Socket实现)

目录 介绍 Web Server在Web架构系统中的作用 Web Server与Web网站程序的交互 HTTPListener与Socket两种方式的差异 附带Demo源码概述 Demo效果截图 总结 介绍 本篇文章主要介绍使用HTTPListener类型自己动手创建一个Web Server,创建的Web Server能够接收来自浏览器端的HTTP请求,并且能够传递给对应的Web站点进行处理,最后将处理结果(Html或者其他格式)返回给浏览器. 博主前面曾经介绍过使用Socket模拟Web Se

flask 创建一个web

创建一个web pip install flask from flask import Flask app=Flask(__name__) @app.route('/') def index(): return 'hello' 运行 flask run 原文地址:https://www.cnblogs.com/buchizaodian/p/11142154.html

express创建一个工程测试

创建一个工程 现在已经有express 键入:express myapp (myapp是随意起的工程名称) 你会发现多了一个 C:\Program Files\nodejs\myapp 目录 默认情况下:里会自动创建 这几个文件,不做解释,相信有过开发经验的同学都能一眼明了. 复制node_modules到myapp下面 环境搭建到此完工,下面做一个demo测试! 在myapp下新建helloworld.js复制代码 代码如下: var http = require("http");h