2013-08-19 4 views
0

노드 NPM의구성 NPM

  • 나는 세계에서 내 시스템에 httpster를 설치 한

  • 는 표현 httpster 수준, 내 프로젝트 디렉토리 & 디렉토리 다음 내용은 D:\Project\Demo\Node입니다.

    /Node 
    - index.html 
    - style.css 
    - server.js 
    

    나는이 server.js 파일에있는 모든 내 서비스 방법 작성했습니다. 다음은 내 server.js의 내용이 내 프로젝트가 단순히

    cd "d:\Project\Demo\Node\" 
    

    아래로 내 프로젝트 폴더로 이동 명령 httpster를 실행 실행

    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); 
        }); 
    }); 
    

    을 제기하고 기본 포트 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에서 내 서비스를 어떻게 사용합니까?

  • +0

    를 제공하는

    app.use(express.static(path)); 

    같은 라인을 포함해야, 하나의 로컬 호스트 포트에서 ExpressJS. 내가 생각하는 바른 길인가? –

    답변

    2

    httpster는 정적 콘텐츠 만 제공합니다. 그래서 당신이하고있는 일은 '정적 인'서버를 만들어 브라우저에서 3 개의 파일에 액세스 할 수있게하는 것입니다. 하지만 server.js이 실행되도록하려면이 server.js

    실행되지 않을 것이다, 당신은 전화를해야 노드 server.js

    그러나 이미 명시 사용하는 경우, 당신은 왜 httpster를 사용 하시겠습니까? 당신은 단지 모든 정적 파일

    내가 백본 및 노드 내 서비스 내 프로젝트를 실행하려면
    +0

    예! 나는 그것을 얻었다, 나는이 선을 가지지 않고 있었다. 감사. –

    +1

    예! 당신이 맞다면 Express가있을 때 HTTPSter가 필요 없다. –