【发布时间】:2013-08-19 15:56:56
【问题描述】:
我正在做一些演示项目,我正在使用以下 Node NPM 的
- httpster
- 快递
我已经在我的系统中安装了全局级别的 httpster,我的项目目录是 D:\Project\Demo\Node 内容如下文件和目录。
/Node
- index.html
- style.css
- server.js
我已经在这些 server.js 文件中编写了我所有的服务方法。 以下是我的 server.js 文件的内容
var express = require('express')
, http = require('http')
, app = express()
, http = require('http')
, path = require('path');
app.configure(function() {
app.use(express.bodyParser());
app.set(express.methodOverride());
app.set(express.router);
});
app.get('/', function() {
sequelize.query("SELECT * FROM users_tbl").success(function(rows) {
console.log(rows);
}).error(function(error) {
console.log(error);
});
});
app.post('/user', function(req, res) {
sequelize.query("INSERT INTO users_tbl (firstname,lastname) VALUES ('"+req.body.firstname+"','"+req.body.lastname+"')").success(function() {
console.log("Data Inserted");
}).error(function(error) {
console.log(error);
});
});
app.put('/user/:id', function(req, res) {
sequelize.query("UPDATE users_tbl SET lastname='"+req.body.lastname+"' WHERE id='"+req.params.id+"'").success(function() {
console.log("Data Updated");
}).error(function(error) {
console.log(error);
});
});
app.del('/user/:id', function(req, res) {
sequelize.query("DELETE FROM users_tbl WHERE id='"+req.params.id+"'").success(function() {
console.log("Data Delete");
}).error(function(error) {
console.log(error);
});
});
要运行我的项目,我只需导航到我的项目文件夹,如下所示
cd "d:\Project\Demo\Node\"
然后运行 httpster 命令,它在默认端口 3333 下运行
http://localhost:3333 => reads my index.html successfully, but no service is run.
http://localhost:3333/user => this too don't work.
我猜,我的 httpster 对我的 server.js 没有参考。那么如何通过 httpster npm 使用我的服务呢?
【问题讨论】:
-
我想在一个本地主机端口上运行我在 Backbone 中的项目和我在 Node、ExpressJS 中的服务。我的想法正确吗?