小编Amo*_*itz的帖子

node.js process.env 无法在命令行中工作

我正在学习从头开始编写区块链的在线课程。本课程使用 JavaScript 和 Node.js。我对这些技术非常陌生,但到目前为止,我已经遵循了该课程。我正在粘贴相关代码 - 应用程序文件(索引):

const express = require('express');
const bodyParser = require('body-parser');
const Blockchain = require('../blockchain');
const P2pServer = require('./p2p-server');

const HTTP_PORT = process.env.HTTP_PORT || 3001;

const app = express();
const bc = new Blockchain();
const p2pServer = new P2pServer(bc);

app.use(bodyParser.json());

app.get('/blocks', (req, res) => {
    res.json(bc.chain);
});

app.post('/mine', (req, res) => {
    const block = bc.addBlock(req.body.data);
    console.log(`New blovk added: ${block.toString()}`);

    res.redirect('/blocks');
});

app.listen(HTTP_PORT, () => console.log(`Listening on port ${HTTP_PORT}`));
p2pServer.listen();
Run Code Online (Sandbox Code Playgroud)

以及 p2p-server.js 中的代码:

const Websocket = require('ws'); …
Run Code Online (Sandbox Code Playgroud)

environment command-line node.js

2
推荐指数
1
解决办法
2186
查看次数

求职面试测试 - 找出两个字符中第一个出现在字符串中的索引

我刚刚进行了在线访谈,并被问到一个简洁的问题.以为我会与社区分享,以及我的回答.看看你认为我的答案是否正确,如果没有 - 你会如何改进?我认为这可以让像我这样的人有相对较短的编码经验,试图迈出第一步.

注意 - 这个问题在正文中没有解释 - 必须自己弄清楚功能.什么函数的作用是返回的第一个实例char achar b特定的String s或-1,如果不是没有发现.

问题

尽可能简化下面的实现.如果您还可以提高性能作为简化的一部分,那就更好了!仅供参考:此代码超过35行和300多个令牌,但它可以写成5行和少于60个令牌.

static int func(String s, char a, char b)
{
    if (s.isEmpty()) return -1;

    char[] strArray = s.toCharArray();

    int i=0;
    int aIndex=-1;
    int bIndex=-1;
    while (aIndex==-1 && bIndex==-1 && i<strArray.length)
    {
        if (strArray[i] == a)
            aIndex=i;
        if (strArray[i] == b)
            bIndex=i;
        i++;
    }


    if (aIndex != -1)
    {
        if (bIndex == -1)
            return aIndex;
        else
            return Math.min(aIndex, bIndex);
    }
    else
    {
        if …
Run Code Online (Sandbox Code Playgroud)

java indexof

0
推荐指数
1
解决办法
2375
查看次数

标签 统计

command-line ×1

environment ×1

indexof ×1

java ×1

node.js ×1