我正在做一些演示项目,我正在使用以下 Node NPM
- 网址
- 表示
我已经在全局级别的系统中安装了 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 一起使用?