最近很多小伙伴都在问javascript–如何使用node.js的readline模块连续两次输入?和nodejsfor循环这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展java
最近很多小伙伴都在问javascript – 如何使用node.js的readline模块连续两次输入?和nodejsfor循环这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展javascript – Node.js的循环模块、javascript – NodeJS的Excel模块、javascript – Node’readline’模块没有’end’事件 – 当没有更多的行时,我该怎么办?、javascript – Typescript:如何解析node.js的绝对模块路径?等相关知识,下面开始了哦!
本文目录一览:- javascript – 如何使用node.js的readline模块连续两次输入?(nodejsfor循环)
- javascript – Node.js的循环模块
- javascript – NodeJS的Excel模块
- javascript – Node’readline’模块没有’end’事件 – 当没有更多的行时,我该怎么办?
- javascript – Typescript:如何解析node.js的绝对模块路径?
javascript – 如何使用node.js的readline模块连续两次输入?(nodejsfor循环)
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin,output: process.stdout }); const r2 = readline.createInterface({ input: process.stdin,output: process.stdout }); rl.question('Please enter the first number',(answer1) => { r2.question('Please enter the second number',(answer2) => { var result = (+answer1) + (+answer2); console.log(`The sum of above two numbers is ${result}`); }); rl.close(); });
这个程序只显示“请输入第一个数字”,当我输入一个像5这样的数字时,第二个输入也需要5个并显示答案10
它根本不问第二个问题.请检查一下,告诉我是什么问题.如果有更好的方法可以采取多种输入,请告诉我们.
我是node.js的初级用户
解决方法
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin,output: process.stdout }); rl.question('Please enter the first number : ',(answer1) => { rl.question('Please enter the second number : ',(answer2) => { var result = (+answer1) + (+answer2); console.log(`The sum of above two numbers is ${result}`); rl.close(); }); });
javascript – Node.js的循环模块
几分钟前我问过循环,见Asynchronous for cycle in JavaScript.
这一次,我的问题是 – Node.js有什么模块吗?
for ( /* ... */ ) {
// Wait! I need to finish this async function
someFunction(param1,praram2,function(result) {
// Okay,continue
})
}
alert("For cycle ended");
编辑:更新了代码.
function asyncLoop(iterations,func,callback) {
var index = 0;
var done = false;
var loop = {
next: function() {
if (done) {
return;
}
if (index < iterations) {
index++;
func(loop);
} else {
done = true;
callback();
}
},iteration: function() {
return index - 1;
},break: function() {
done = true;
callback();
}
};
loop.next();
return loop;
}
exports.asyncFor = asyncLoop;
还有一个小测试:
// test.js
var asyncFor = require('./aloop').asyncFor; // './' import the module relative
asyncFor(10,function(loop) {
console.log(loop.iteration());
if (loop.iteration() === 5) {
return loop.break();
}
loop.next();
},function(){console.log('done')}
);
休息取决于你,不可能使这100%通用.
javascript – NodeJS的Excel模块
有没有稳定的nodejs模块用于生成简单的Excel页面?
解决方法
我之前使用过Microsoft规范文档来弄清楚如何实现仅为我的特定用例提供服务的部分(不完整)系统.换句话说,如果你能找出你需要的确切位数(即只是将一个二维数组转换成一些excel行),那么你可以经常忽略其余的规范,因为它不适用于你.
我还发现,查看用其他语言编写的解决方案对我有帮助 – 例如,here’s a project使用c#.
根据后端系统上可用的内容,您可以使用spawn a child process来处理转换.
或者,您可以将整个内容卸载到Web服务. Google Documents List API允许您存储和操作Google Docs文件,然后使用Google Spreadsheets API,您可以阅读和修改Google Spreadsheets中的数据.
我发现这些都没有真正解决你的图书馆可用性问题,但可能会给你一种解决问题的新方法.
javascript – Node’readline’模块没有’end’事件 – 当没有更多的行时,我该怎么办?
试
reader.on('end',cb);
不行
一旦没有更多的行被读取,我该如何运行回调?
解决方法
reader.on('close',cb);
javascript – Typescript:如何解析node.js的绝对模块路径?
我需要基于baseUrl解析模块,因此输出代码可用于node.js
这是我的src / server / index.ts
import express = require('express');
import {port,databaseUri} from 'server/config';
...
这是我的src / server / config / index.ts
export const databaseUri: string = process.env.DATABASE_URI || process.env.MONGODB_URI;
export const port: number = process.env.PORT || 1337;
运行tsc我能够编译没有错误的所有文件,但是输出:dist / server / index.js是
"use strict";
var express = require("express");
var config_1 = require("server/config");
...
结果找不到模块’server / config’如果我试图将它与node dist / sever / index.js一起使用.
为什么服务器/配置路径没有以任何方式解析,因此可以使用已编译的代码或如何解决它.或者我在做什么或者想错的方式?
我的tsc –version是2.1.4
这是我的tsconfig.json:
{
"compileOnSave": true,"compilerOptions": {
"baseUrl": "./src","rootDir": "./src","module": "commonjs","target": "es5","typeRoots": ["./src/types",".node_modules/@types"],"outDir": "./dist"
},"include": [
"src/**/*"
],"exclude": [
"node_modules","**/*.spec.ts"
]
}
注意我不想使用../../../../relative路径.
this feature,along with the rest of the module resolution
capabilities,are only to help the compiler find the module source
given a module name. no changes to the output js code. if you require
“folder2/file1” it will always be emitted this way. you might get
errors if the compiler Could not find a folder2/file1.ts,but no
change to the output.
07001
和
The compiler does not rewrite module names. module names are
considered resource identifiers,and are mapped to the output as they
appear in the source
07002
因此,typescript中发出的JS不会重写您提供给需要的已发现模块的模块路径.如果您在编译后在节点中运行您的应用程序(它看起来像是快递),那么它将使用node module system解决打字稿编译后的模块引用.这意味着它只会尊重模块中的相对路径,然后它将回退到node_modules以查找依赖项.
that is how it is meant to work. the compiler needs the paths to find
the declaration of your module. module names are resource identifiers
and should be emitted as is and not altered.
07004
您已经基本确认了这个问题中的发出输出.
今天关于javascript – 如何使用node.js的readline模块连续两次输入?和nodejsfor循环的讲解已经结束,谢谢您的阅读,如果想了解更多关于javascript – Node.js的循环模块、javascript – NodeJS的Excel模块、javascript – Node’readline’模块没有’end’事件 – 当没有更多的行时,我该怎么办?、javascript – Typescript:如何解析node.js的绝对模块路径?的相关知识,请在本站搜索。
本文标签: