我有一个反向代理背后的应用程序,我希望它只能听localhost/127.0.0.1.
我希望这可行:
app.listen(3001, 'localhost');
要么
app.listen(3001, '127.0.0.1');
...但我得到一个错误:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property 'port' of null
at Object.<anonymous> (/home/ctoledo/hive-go/go.js:204:76)
at Module._compile (module.js:441:26)
at Object..js (module.js:459:10)
at Module.load (module.js:348:31)
at Function._load (module.js:308:12)
at Array.0 (module.js:479:10)
at EventEmitter._tickCallback (node.js:192:40)
Run Code Online (Sandbox Code Playgroud)
在没有指定主机名的情况下运行应用程序可以正常工作,即app.listen(3001);.
我正在运行Node v0.6.14并表达@ 2.5.5并已阅读此google小组讨论并在Express application.js中发现此评论说:"此方法采用与节点相同的参数http.Server#listen()."
谢谢你的帮助.
我想将音频文件(ogg和/或mp3)的波形渲染到canvas元素.
我想知道是否有任何库会使这个变得简单?我正在寻找这样的结果:http://plucked.de/
我刚刚开始使用Express(2.5.5)的新版本,默认情况下会创建一个./routes目录./views和./public
路线内有一个index.js文件,其中包含:
/*
* GET home page.
*/
exports.index = function(req, res){
res.render('index', { title: 'Express' })
};
Run Code Online (Sandbox Code Playgroud)
默认情况下(express从命令行运行后),这是main中的routes部分app.js:
// Routes
app.get('/', routes.index);
Run Code Online (Sandbox Code Playgroud)
我在main中为redis客户端设置了一个变量app.js:
var redis = require('redis'),
db = redis.createClient();
Run Code Online (Sandbox Code Playgroud)
我想知道如何访问包含在其中的文件中的方法db(以及我require在其中的任何其他模块app.js)./routes
if...true条件工作就像文档中概述的魅力一样.
但如果我尝试做类似的事情:
{% if !posts.length %}
<i>No project posts yet!</i>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
Template render error: (/home/nak/clones/mf3/views/project.html) [Line 10, Column 9]
unexpected token: !
Run Code Online (Sandbox Code Playgroud)
我通过以下方式解决了这个问题:
{% if posts.length %}
{% else %}
<i>No project posts yet!</i>
{% endif %}
Run Code Online (Sandbox Code Playgroud)
有没有更好(正确)的方法来做到这一点?
我正在做一些较旧的C书[ANSI C的第一本书]中的一些例子,并在尝试编译此示例代码时遇到错误:
#include <stdio.h>
struct tele_typ {
char name[30];
char phone_no[15];
struct tele_typ *nextaddr;
};
main() {
struct tele_typ t1 = {"Acme, Sam", "(201) 555-6678"};
struct tele_typ t2 = {"Dolan, Edith", "(213) 682-3104"};
struct tele_typ t3 = {"Lanfrank, John", "(415) 718-4581"};
tele_typ *first; /* create a pointer to a structure */
first = &t1; /* store t1's address in first */
t1.nextaddr = &t2; /* store t2's address in t1.nextaddr */
t2.nextaddr = &t3; /* store t3's address in t2.nextaddr …Run Code Online (Sandbox Code Playgroud) 这可能与异步代码有关,但我不确定是什么。当我将它们分开时,两者都会通过:mocha test/models.coffee和mocha test/login.coffee
但是describe 'saving another user with same username', ->当我与npm test. 我想数据库在运行该步骤时会被清除,因此它会保存而不是产生错误,因为它应该是一个唯一值。
另外:我对这个软件测试的东西非常陌生,如果有人有任何提示,或者想批评我公然的错误,请随时给我发电子邮件(查看我的个人资料)
谢谢!!
这是我的两个测试文件(咖啡脚本):
/test/models.coffee
should = require 'should'
{User} = require '../models'
# function to find our test user, John Egbert
findJohn = (cb) ->
User.findOne {'public.username': 'john'}, (err, john) ->
throw err if err
cb(john)
before (done) ->
# Drop all users from database
User.collection.drop()
# Create our test user, his username is John Egbert
User.create
password: 'test123'
public: …Run Code Online (Sandbox Code Playgroud) 文档讨论了如何使用各种中间件(app.use),但我找不到ExpressJS站点上可用的中间件列表!
我之前使用过redis-cli(不确定是否在这个盒子上),但是现在它给了我这个:
nak@none:~$ redis-cli
usage: redis-cli [-h host] [-p port] [-r repeat_times] [-n db_num] cmd arg1 arg2 arg3 ... argN
usage: echo "argN" | redis-cli [-h host] [-p port] [-r repeat_times] [-n db_num] cmd arg1 arg2 ... arg(N-1)
If a pipe from standard input is detected this data is used as last argument.
example: cat /etc/passwd | redis-cli set my_passwd
example: redis-cli get my_passwd
example: redis-cli -r 100 lpush mylist x
Run Code Online (Sandbox Code Playgroud)
所以,我netcat到redis服务器,我能够沟通:
nak@none:~$ ncat 127.0.0.1 6379
info
$336
redis_version:1.2.0
arch_bits:32
multiplexing_api:epoll …Run Code Online (Sandbox Code Playgroud) 我现在并不担心可移植性,我只是想以/dev/sdb字节为单位读取say的大小.
我试过os.path.getsize('/dev/sdb/')但它返回0.
我也试着做open('/dev/sdb/', 'rb'),并read()和tell()获得计数,但就是太慢.