我检查了两个命令npm start和npm run start,两者完美的作品.我使用了create-react-app.但是为了在CSS模块中进行配置更改,我运行npm eject但是它会引发错误.
但npm run eject有效吗?我很困惑,为什么npm eject不工作.我可以配置吗?
以下是我的package.json:
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
Run Code Online (Sandbox Code Playgroud) 我有一个缩小的 js 文件,我需要在上面放置一个断点。在 Chrome 和 IE 11 中,我可以选择漂亮打印,但在 Edge 中我看不到漂亮打印选项。
我是否需要在选项或其他地方启用漂亮的打印选项,或者 Edge 没有该选项。
我在Google上搜索过,但都显示了Chrome和IE 11的方法。我没有找到Edge漂亮打印的相关文章。
注意:{} - Chrome 和 IE 11 的漂亮打印效果完美。
我尝试过的
没有看到“{}”图标
我有一个使用 Redis 的 Node.js 应用程序,我试图连接 Docker 容器和本地运行的 Redis。
尝试过的解决方案:
vim /usr/local/etc/redis.conf
更新
bind 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
到
bind 0.0.0.0
Run Code Online (Sandbox Code Playgroud)
停止redis并再次启动它并尝试运行docker
通过上面的事情尝试运行docker run -p 4000:8080 -p 6379:6379 -t node-app
上面两者都不起作用,出现以下错误
Error: Redis connection to localhost:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
Run Code Online (Sandbox Code Playgroud)
更新:我正在Mac上检查它。
我正在尝试在节点js中实现一个记录器,它将在日志的自定义格式上每天创建一个新的日志文件
为此,我使用了三个包
所以每天应该在日志文件夹中创建一个新的日志文件的最终输出,它应该将所有http(摩根日志)和键入的日志(winston日志)记录到以下格式的单个文件中
日期|| 文件名|| statusCode || logMessage || uuid(用于追踪)
例如:Fri Jan 18 2019 13:48:18 GMT + 0530(IST)|| [index.js] || 200 || 调用新路径|| 287dccb0-1afa-11e9-88a0-dfb1c665be9d
所以为此,我写了三个文件index.js(nodejs的根文件)logger.js(logger实现和配置)和logger.test.js(使用jest的logger测试用例)
额外的包
我遇到的问题
// index.js
const app = require('express')();
const cors = require('cors')
const morgan = require('morgan') // HTTP request logger middleware
const logger = require('./config/logger')(module) //Logger
const …Run Code Online (Sandbox Code Playgroud)I am trying to extract the keys of each object in the array, then i will collect all the keys , after that i concatenate the small chunk key arrays. Then i use set to eliminate duplicates and get all the keys.
I am able to get the result. Is there any better approach for this
Any help appreciated
let data = [
{
"test1": "123",
"test2": "12345",
"test3": "123456"
},
{
"test1": "123",
"test2": "12345",
"test3": "123456"
},
{ …Run Code Online (Sandbox Code Playgroud)我如何在 es6 类上测试 catch 块
const fs = require('fs');
class Service {
constructor(accessToken) {
this.accessToken = accessToken;
}
async getData() { // eslint-disable-line class-methods-use-this
try {
const data = fs.readFileSync(`${__dirname}/models/mockData.json`, { encoding: 'utf8' });
const returnData = JSON.parse(data);
return returnData;
} catch (err) {
return err;
}
}
}
module.exports = Service;
Run Code Online (Sandbox Code Playgroud)
使用笑话我如何编写测试用例来覆盖 catch 块。
我如何测试下面我使用类的代码片段中的 catch 块
// 示例.js
class Sample{
constructor(data){
this.resolvedData = this.retrieveData(data)
}
retrieveData(data){
try{
const resolvedData = data.map(o => o.name);
}catch(error){
throw error
}
}
}
Run Code Online (Sandbox Code Playgroud)
// 示例.test.js
const Sample = require('./Sample');
describe('Sample File test cases', () => {
test('should return the resolvedData', () => {
const resolvedSample = [{name: "John", id: 123}, {name: "Doe", id: 3432}]
const model = new Sample(resolvedSample);
const expectedResolvedSample = [{name: "John"}, {name: "Doe"}]
expect(model).toEqual(expectedResolvedSample)
})
test('should throw an error', () => {
const resolvedSample …Run Code Online (Sandbox Code Playgroud) 我有一个数组 as ,我需要删除空值并用零替换它。
我已经做到了这么多。当我检查数组长度为 8 时,它只显示 2 个元素。用零替换它的最佳方法是什么。
var a = [];
a[3] = 5
a[5] = 15
console.log(a.length) // 6
console.log(a) // [empty,empty,empty,5,empty,15]
how can i make the output as [0,0,0,5,0,15]
Run Code Online (Sandbox Code Playgroud)
// 试过这种方法没有用
a.map(o => o !== null ? o : 0)
Run Code Online (Sandbox Code Playgroud) 基本上我正在尝试使用摩根和温斯顿为 nodejs 实现记录器。
当我尝试使用 morgan 时,抛出 stream.write 错误不是函数。
因为我想获取文件名,所以我正在传递模块,从模块对象中有一个名为 filename 的属性。
下面是我的代码。
// 温斯顿.js
const appRoot = require('app-root-path');
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const path = require('path');
// Custom Format
const customFormat = printf(info => {
return `${new Date(info.timestamp)} || [${info.label}] || ${info.level}: ${info.message} `
})
// Return the last folder name in the path and the calling
// module's filename.
const getLabel = function (moduleDetails) {
if …Run Code Online (Sandbox Code Playgroud) 如何在useEffect钩子的 if 块内调用 redux 操作:
useEffect(async () => {
if (nameId && selectedGroup === 'AGM') {
const subPeople = await getSubPeople(nameId);
}
}, [nameId, selectedGroup]);
Run Code Online (Sandbox Code Playgroud)
我有两个选择框。如果用户在name选择框中键入内容,我会将选定的 ID 存储name在nameId状态中。如果用户选择一个组,我会将其存储在 中selectedGroup,因此只有当两个条件都匹配时,我才需要调用 API 端点来获取subPeople.
如果我评论这段代码就没有错误。我怎样才能使代码片段发挥作用?