如何使用node.js \ r \ n回车/换行并表达

时间:2018-10-15 00:52:34

标签: node.js regex newline

我希望这样:

I <3cookies 127.0.0.2

和牛奶

o_O

var express = require('express');
var app = express();
host = '127.0.0.2'; // Choose a different loopback address;
port = "5555"

app.get('/', function (req, res) {
    res.send("I<3cookies " + host + "\r\n with milk" + "\r\no_O");
});

app.listen(port, host, function () {
    console.log("Listening in on: " + host + port);
});

到目前为止,当我运行它时,它看起来像: 我<3个饼干127.0.0.1加牛奶o_O

1 个答案:

答案 0 :(得分:1)

res.send(`I<3cookies ${host}

with milk

o_O`);

在Chrome控制台中测试

> host = '127.0.0.1'
< "127.0.0.1"
> "I<3cookies " + host + [^\r\n] + "with milk" + [^\r\n] + "no_O"
< VM5323:1 Uncaught SyntaxError: Unexpected token ^
> `I<3cookies ${host}

with milk

o_O`
< "I<3cookies 127.0.0.1

with milk

o_O"