小编Ste*_*ast的帖子

NodeJS - WinstonJS - 清除日志文件

我正在使用 WinstonJS 记录到文件,并nodemon在我更新代码时重新启动。

var winston = require('winston');

var logger = new (winston.Logger)({
    transports: [
        new (winston.transports.File)({
            level: 'silly',
            filename: __dirname + '/logs/test.log',
            json: false
        })
    ]
});

logger.log('info', 'something');
Run Code Online (Sandbox Code Playgroud)

日志文件被附加到,但是当我更改代码并保存我的文件时,nodemon再次运行它并再次附加日志文件。这导致日志文件越来越长,我必须不断手动删除内容。

我想我可以用这个fs模块做一些事情,但使用 Winston 说类似的东西会好得多update: replace|append,但我看不到任何可用的东西。

有什么办法可以清除日志文件,所以我只有上次运行代码时的日志条目..?

node.js nodemon

6
推荐指数
2
解决办法
3607
查看次数

PayPal TLS测试URL - PHP卷曲SSL协议错误

我正在尝试测试一个新的PayPal测试端点:https://tlstest.paypal.com.

请参见本页底部:TLS 1.2和HTTP/1.1升级Microsite(验证您的...).

我在Windows Server 2008 R2和IIS 7.5上使用PHP(5.3.28)和curl(7.30.0 - OpenSSL/0.9.8y - libssh2/1.4.2):

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://tlstest.paypal.com');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2
$result = curl_exec($ch);
echo 'result = '.$result.'<br>';
echo 'errno = '.curl_errno($ch).'<br>';
echo 'error = '.curl_error($ch).'<br>';
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

35与tlstest.paypal.com:443相关的未知SSL协议错误

我发现了这个:Github - 未知的SSL协议错误,其中有人说:

对于TLS 1.2,Openssl必须为1.0.1或更高.

它是否正确..?

我的PHP OpenSSL是版本:( OpenSSL/0.9.8y来自phpinfo()).

如果你确实需要OpenSSL 1.0.1或更高版本来使用TLS 1.2,那么大概每个运行PHP的服务器都使用较少的OpenSSL版本(我猜这很多!)将很快无法使用任何PayPal API或PayPal IPN.

如何在Windows上更新我的PHP OpenSSL版本..?

php ssl curl paypal

6
推荐指数
1
解决办法
6526
查看次数

windows启动时使用批处理文件启动pm2?

我无法让pm2在 Windows 上启动我的应用程序。我正在运行 Windows Server 2012 R2 Standard 和pm2 2.4.2.

我有一个pm2 进程文件,我用它来启动我的所有应用程序。

c:\pm2\process.json

{
  "apps": [
    {
      "name" : "my-app",
      "script" : "c:\\node\\myapp\index.js"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我有一个使用 JSON 文件的批处理文件:

c:\pm2\pm2-startup.bat

@echo off

set HOMEDRIVE=C:
set PM2_HOME=C:\etc\.pm2
setx /M PM2_HOME C:\etc\.pm2

cd C:\pm2 & pm2 start process.json
Run Code Online (Sandbox Code Playgroud)

我安排了一个 Windows 任务来运行批处理文件:

  • 触发:启动时
  • 运行方式:管理员帐户
  • 无论用户是否登录都运行:
  • 以最高权限运行:
  • 行动:启动一个程序
    • 脚本:C:\pm2\pm2-startup.bat
    • 开始于:C:\pm2

如果我手动运行批处理文件(双击它),它就可以工作。如果我手动运行计划任务(右键单击,运行),它就可以工作。

当我重新启动服务器并检查计划任务时,它已运行,没有错误,但应用程序未运行。执行后pm2 list显示表中没有应用程序。

我不想使用 pm2-windows-service因为我不想将 pm2 作为服务运行(尝试过,但很不稳定)。

我也不想使用 …

windows batch-file pm2

6
推荐指数
1
解决办法
1万
查看次数

CSS BEM,修饰符的字符是什么..?

我不确定哪个是官方网站,我找到了getbem.comen.bem.info

一种建议使用--修饰符(Naming):

CSS 类由块或元素的名称加上两个破折号组成。

另一个_用于修饰符(修饰符名称):

修饰符名称由单个下划线 (_) 分隔。

我知道我可以使用任何一个,而且保持一致确实很重要,但我喜欢尽可能尝试使用官方规范。

  • 哪个是官方网站..?
  • 我真的应该使用--还是_用于修饰符..?

css bem

6
推荐指数
1
解决办法
363
查看次数

NodeJS new Agent()和HTTP Keep-Alive标头之间的区别..?

我正在使用axios发出HTTP请求。

当在Node中使用时,axios提供了new http.Agent()请求配置中指定的选项。

HTTP代理选项有:

const agentOptions = {
  keepAlive: true,      // Keep sockets around even when there are no outstanding requests, so they can be used for future requests without having to reestablish a TCP connection. Defaults to false
  keepAliveMsecs: 1000, // When using the keepAlive option, specifies the initial delay for TCP Keep-Alive packets. Ignored when the keepAlive option is false or undefined. Defaults to 1000.
  maxSockets: Infinity, // Maximum number …
Run Code Online (Sandbox Code Playgroud)

keep-alive node.js axios

6
推荐指数
1
解决办法
782
查看次数

Mailchimp RESTful API 3.0 HTTP基本身份验证

我正在尝试使用带有基本身份验证的Mailchimp API 3.0版.我正在使用经典ASP.

Json响应总是:"API Key Missing".

Set HttpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
HttpReq.open "GET", "https://us4.api.mailchimp.com/3.0/", False
HttpReq.setRequestHeader "Content-Type", "application/json"
HttpReq.setRequestHeader "apikey", "xxxxxx"
HttpReq.send ""
Response.Write  HttpReq.ResponseText
Set HttpReq = Nothing
Run Code Online (Sandbox Code Playgroud)

我将它作为标题发送.

我究竟做错了什么..?

asp-classic mailchimp mailchimp-api-v3.0

5
推荐指数
1
解决办法
4613
查看次数

HTTP请求获取HTTP状态码,但没有内容

我正在使用axios获取 URL 的 http 状态:

async function getUrlHttpStatus (url) {
  try {
    const res = await axios({ method: 'get', url })
    return {
      status: res.status,
      statusText: res.statusText
    }
  } catch (err) {
    return {
      status: err.response.status,
      statusText: err.response.statusText
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

显然,这也会从该 URL 中返回所有内容,如果内容很多,速度可能会非常慢。

有没有一种方法可以发出 HTTP 请求,获取 HTTP 状态代码,而无需从 URL 下载所有内容,因此速度很快......?

javascript http node.js axios

5
推荐指数
1
解决办法
1227
查看次数

node-mssql事务插入 - 返回插入的id ..?

我正在使用node-mssql3.2.0,我需要INSERT INTO一个表并返回插入记录的id.

我可以成功地使用sql.Transaction()插入数据,但给回调(request.query()transaction.commit())的唯一参数是:

const request = new sql.Request();
request.query('...', (err, recordset, affected) => {});

const transaction = new sql.Transaction();
transaction.commit((err) => {});
Run Code Online (Sandbox Code Playgroud)

所以,recordsetundefinedINSERT,UPDATEDELETE语句,并affected为受影响的行数,在我的情况1.

有没有人知道在使用后获取插入记录ID(只是主键id)的好transaction.commit()方法node-mssql

javascript sql sql-server node.js node-mssql

4
推荐指数
1
解决办法
3014
查看次数

RESTful API - 删除一些资源集合?

我可以DELETE使用单个资源,例如:

// Removes group 12 from employee 46
DELETE /employees/46/groups/12
Run Code Online (Sandbox Code Playgroud)

我可以DELETE像一个完整的资源集合:

// Removes all groups from employee 46
DELETE /employees/46/groups
Run Code Online (Sandbox Code Playgroud)

我正在寻找DELETE 一些资源集合的正确 RESTful 方式。

  1. DELETE /employees/46/groups { ids: [12, 15, 32] }
  2. DELETE /employees/46/groups?ids=12,15,32
  3. DELETE /employees/46/groups/xx (单个,但调用它 3 次)

查询字符串参数 ( ?ids=12,15,32)应该只与GET..一起使用吗?

请求正文 ( { ids: [12, 15, 32] })是否应该始终与POST,PUTDELETE..一起使用?

所有这三个都可以工作,但是哪一个是DELETE仅某些资源集合的标准方法..?

rest http

4
推荐指数
1
解决办法
2834
查看次数

CSS BEM 子标签选择器?

使用 CSS BEM 方法...

假设我有一些 HTML,像这样(这只是为这个问题组成的示例 HTML):

<section>
  <div>
    <p>Text.</p>
    <p>Text.</p>
    <p>Text.</p>
    <p>Text.</p>
    <p>Text.</p>
  </div>
</section>
Run Code Online (Sandbox Code Playgroud)

从我读过的内容来看,我应该这样做:

.section { ... }
.section__sometext { ... }
.section__text { ... }

<section class="section">
  <div class="section__sometext">
    <p class="section__text">Text.</p>
    <p class="section__text">Text.</p>
    <p class="section__text">Text.</p>
    <p class="section__text">Text.</p>
    <p class="section__text">Text.</p>
  </div>
</section>
Run Code Online (Sandbox Code Playgroud)

而不是这样:

.section {}
.section__sometext { ... }
.section__sometext p { ... }

<section class="section">
  <div class="section__sometext">
    <p>Text.</p>
    <p>Text.</p>
    <p>Text.</p>
    <p>Text.</p>
    <p>Text.</p>
  </div>
</section>
Run Code Online (Sandbox Code Playgroud)

可以使用.section__sometext p { ... }..吗?

p遇到的问题是可能有很多很多's,并且给它们所有长的类名似乎是浪费时间和标记。

使用.section__sometext …

css bem

4
推荐指数
1
解决办法
1075
查看次数