我试图在流行的LearnYouNode程序的帮助下自学Node .我正在练习6题为' Make it Modular '.基本上我必须创建一个模块,然后在我的主要需要它program.js并满足一些条件.
其中一个条件表明,如果出现错误,我必须调用回调函数,只传递错误对象并保留第二个参数null.
这是我目前的模块代码:
var fs = require('fs'); // require file stream module
var pathMod = require('path'); // require path module
var i = 0; // local variable
var fileName = []; // local array variable
module.exports = function (path, ext, callback) {
return {
process: function () {
fs.readdir(path, callback);
},
success: function (ext, files) {
for(i; i < files.length; i++) {
var currentFile = files[i];
var …Run Code Online (Sandbox Code Playgroud) 我想知道你将如何使用打字稿IOC专门节点应用程序.
在基于外部模块的体系结构的情况下,应用程序中没有任何类.只是纯模块,因为我的应用程序在很大程度上取决于node_modules.
在这种情况下,我如何整合IOC解决方案?有什么想法吗?
以下是我希望使用IOC的具体案例:
我有猫鼬模型:
interface IStuffModel extends IStuff, mongoose.Document { }
var Stuff= mongoose.model<IStuffModel>('Stuff', Schemas.stuffSchema);
export = Stuff;
Run Code Online (Sandbox Code Playgroud)
和相关的假类:
export class Stuff implements IStuff {
//do stuff
}
Run Code Online (Sandbox Code Playgroud) 几乎每次我npm用来安装软件包时,都会收到如下警告:
npm WARN deprecated minimatch@1.0.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
Run Code Online (Sandbox Code Playgroud)
然后我安装带有建议版本号的可疑软件包。
有没有办法npm自动做到这一点?当然风险自负。
我的情况
我已经在 Ubuntu 14.04 上使用n安装了 Node v6.2.0 版本。它位于路径/usr/local/n/versions/node/6.2.0 下(通过使用npm 前缀 -g)。
我的全局包安装在lib/node_modules下的那个目录中,但我不能从命令行全局使用这些包。
注意 早些时候我使用旧版本的 Nodejs 5 以不同的方式安装。使用该版本的 Node 全局安装的软件包现在可用,但不是我现在安装的新软件包。
我的问题
是否有技巧或东西指向可以全局使用其包的node_modules目录?
我正在研究具有几个依赖项的 npm 模块。现在,我是否应该通过 node_modules 文件夹将依赖项与我的产品一起发布?
我已经使用过var module = require('/path/to/node_modules/module-name')并且我的所有其他模型都得到了认可,但fs即使我指出了它的位置并确保它已安装,也没有得到认可?我不明白,请帮助
我的控制台给出了这个:http : //prntscr.com/g2akvs
但我所有的其他模块都很好
正如您可以通过我的参考看到的:http : //prntscr.com/g2akzm
我有一个很久以前开始的 NodeJS 项目。在我理解 --save 标志之前,它已经安装了许多软件包。几个版本之前,npm 决定删除 package.json 中未提及的包(这是一件疯狂的事情)。这会导致一个可怕的问题。
现在我明白了 --save 并正确使用它。但是,我无法找到使用未列出的软件包更新 package.json 的方法。
有没有办法让 npm 或其他程序查看项目并添加缺少的依赖项?如果它完全重新创建依赖结构,我会很高兴。
建议?
我有一些图的本地库,需要将其添加到node_modules中。有什么方法可以使用package.json添加此库吗?
我们的package.json看起来像:
{
"name": "name",
"version": "1.01.01",
"scripts": {
...
},
"dependencies": {
...
},
...
}
Run Code Online (Sandbox Code Playgroud)
我的意思是添加类似的内容:
"directory": {
"my-library": "./src/path/to/my/lib"
}
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助。
运行 ng serve 时,我的代码无法编译并出现此错误:
node_modules/@angular/compiler-cli/src/transformers/program.d.ts(9,23) 中的错误:错误 TS2307:找不到模块“路径”。
我认为这与我的本地 angular 版本比我的全局版本旧版本有关,所以我尝试了这个解决方案
但这没有帮助。现在要编译我的代码,我必须删除一个 ';' 在我的项目中随机的某个地方,保存项目,添加分号并保存项目。使用这种方法,我的代码可以编译并且我的应用程序可以运行,但错误仍然存在。
我已经在app.js中使用此代码制作了在控制台中显示端口的信息,但在下面无法正常工作只是整个代码的一部分
const port = 8080;
app.listen(port, () => {
console.log("hi its listening: ${port}!");
});
Run Code Online (Sandbox Code Playgroud)
这是控制台的输出
hi its listening: ${port}!
const express=require('express');
const app=express();
const morgan=require('morgan');
const postRoutes=require("./routes/post");
app.use(morgan("dev"));
app.use('/',postRoutes);
const port = 8080;//process.env.PORT || 8080;
app.listen(port, () => {
console.log("hi its listening: ${port}!");
});
Run Code Online (Sandbox Code Playgroud)
它应该显示:
hi its listening: 8080
Run Code Online (Sandbox Code Playgroud) node-modules ×10
node.js ×7
npm ×5
package.json ×2
angular ×1
angular-cli ×1
callback ×1
express ×1
javascript ×1
json ×1
path ×1
publish ×1
reactjs ×1
typescript ×1
ubuntu ×1