English 中文(简体)
Default Folder Functionality for Node.JS
原标题:Default Folder Functionality for Node.JS
  • 时间:2012-05-17 22:38:17
  •  标签:
  • node.js

我愿在我的网站上增加一些实时功能,包括节点和袖珍,但不必处理页码要求/答复。 曼 谷 我拥有正常的双倍功能,哪里可以提供指数。

感谢!

最佳回答

你可以使用快递框架。 将你的档案置于公共文件夹、你的所有风格、javascript文档和其他超文本文件之下。 你们只需要表明一个切入点,以便提供客户指数。

    var fs = require("fs");
    var express = require("express");
    app = express.createServer();

    app.use(express.static(__dirname +  /public ));
    app.get( / , function(req, res) {
        fs.readFile(__dirname +  /public/index.html ,  utf8 , function(err, text){
            res.send(text);
        });
    });
    app.listen(3000);
问题回答

如果你只想提供静态档案,则使用明示的方式非常简单。

备注文件只需要以下编码线:

    var express = require( express );

    var app = express.createServer(
       express.static(__dirname +  /public )
       );

    app.listen(3000);

您的问世、 c和 j,是你申请的根基。 因此,一个典型的切身之处是:

  app.js
  /public
     index.html
     reset.html
     ...
     ...
     /css
        main.css
        reset.css
        ...
        ...
     /js
        header.js
        util.js
        ...
        ...

我采用了一种略有不同的做法,结果相同:

var express = require( express );
var app = express();

app.use(express.static(__dirname +  /public ));

app.listen(process.env.PORT || 3000);




相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签