标签: express-generator

快递或快递发电机:我需要两者吗?

刚刚探索node.js并遇到了express; 在npm存储库站点https://www.npmjs.com/package/express上明确指出安装是

$ npm install express
Run Code Online (Sandbox Code Playgroud)

但如果我向下滚动快速启动提及

$ npm install -g express-generator@4
Run Code Online (Sandbox Code Playgroud)

有人可以详细解释发生了什么吗?我用谷歌搜索并理解快递v3都捆绑在一起,但在快递v4中,发电机被拉出.

所以我需要同时安装吗?发电机安装是自动表达,而不是反过来?我已经有JS疲劳了,我才开始:-(

补充问题: 然后为了进一步混淆问题,我看到另一个问题,我应该从'npm init'开始并要求表达,或'表达myApp'.现在真的发生了什么,init进入了什么地方?

2017年1月30日更新 我从其他人那里接受了以下答案,但我也添加了自己的答案,这是我当时正在寻找的一个混乱的完全初学者.它可能会帮助别人.

javascript node.js express express-generator

9
推荐指数
1
解决办法
4282
查看次数

为什么使用 bin/www 而不是 index.js?

express-generator工具创建一个名为 的文件bin/www并将其用作应用程序的主要入口点。我相信我已经看到其他几个模块也这样做了,但绝大多数只是使用index.js.

这背后的理由是什么?当然,我理解为什么您要将服务器和用于设置程序的代码拆分为单独的模块,但为什么bin/www而不呢index.js?为什么将主入口点嵌套到比它调用的内容更深两层的程序中?删除文件扩展名,使其更加缺乏描述性?

这背后是否有一个聪明的、不明显的原因?我也应该将其用于我的节点模块吗?

谢谢你!

[编辑]:

所有好的答案,谢谢大家!我已经接受了这一观点,指出这是包含可执行文件的包的标准行为。这是我在这方面遇到的更多阅读:

javascript code-structure node.js express express-generator

7
推荐指数
1
解决办法
4553
查看次数

产生ENOENT node.js错误

我已经使用快速生成器启动了一个node.js应用程序,我有一个奇怪的问题,我无法通过浏览器两次查看页面,第一次加载正常,第二次没有因为节点进程结束以下错误:

GET / 304 412ms

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:988:11)
    at Process.ChildProcess._handle.onexit (child_process.js:779:34)
Run Code Online (Sandbox Code Playgroud)

的package.json

{
  "name": "example01-express",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node-dev ./bin/www"
  },
  "dependencies": {
    "body-parser": "~1.0.0",
    "cookie-parser": "~1.0.1",
    "debug": "~0.7.4",
    "express": "~4.2.0",
    "jade": "~1.3.0",
    "morgan": "~1.0.0",
    "node-compass": "0.2.3",
    "static-favicon": "~1.0.0"
  },
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-contrib-cssmin": "*",
    "grunt-contrib-jshint": "^0.10.0",
    "grunt-contrib-sass": "*",
    "grunt-contrib-uglify": "*",
    "grunt-contrib-watch": "*",
    "grunt-cssc": "*",
    "grunt-htmlhint": "*",
    "matchdep": "*"
  }
}
Run Code Online (Sandbox Code Playgroud)

javascript node.js express express-generator

6
推荐指数
1
解决办法
1万
查看次数

npm 错误!semver.simplifyRange 不是函数

尝试遵循Express入门教程。

我生成了一个应用程序并npm install按照提供的说明运行。

> npx express-generator --view=pug myapp
> npm install
npm ERR! semver.simplifyRange is not a function
npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user/.npm/_logs/2021-03-21T04_58_39_577Z-debug.log
Run Code Online (Sandbox Code Playgroud)

日志中的相关部分

555 http fetch GET 200 https://registry.npmjs.org/longest/-/longest-1.0.1.tgz 706ms
556 timing reifyNode:node_modules/longest Completed in 751ms
557 timing metavuln:cache:get:security-advisory:transformers:qlM2fO34VL+rWNeim/6QsbBJFfHtRf4Z7FAoL1JLqVXlvg5FMRxw1WstcKR09WDDJCiJsPPrdRJugEOTZ6eGZA== Completed in 22ms
558 verbose stack TypeError: semver.simplifyRange is not a function
558 verbose stack     at Advisory.[calculateRange] (/usr/lib/node_modules/npm/node_modules/@npmcli/metavuln-calculator/lib/advisory.js:191:16)
558 verbose stack     at Advisory.load (/usr/lib/node_modules/npm/node_modules/@npmcli/metavuln-calculator/lib/advisory.js:148:28)
558 verbose …
Run Code Online (Sandbox Code Playgroud)

javascript node.js npm express express-generator

6
推荐指数
1
解决办法
2256
查看次数

如何将html-webpack-plugin与现有Express模板一起使用?

我已经安装了express-generetor npm模块,并且喜欢使用玉模板作为模板来构造项目的方式。但是我也喜欢使用HTML-webpack-plugin生成自己的文件,将这两种方法集成在一起的最佳方法是什么?

express-generator html-webpack-plugin

5
推荐指数
1
解决办法
976
查看次数

npm global install提供EISDIR警告和ENOENT错误

我正在尝试使用快速发电机npm install express-generator -g.但是我遇到了错误.

WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/ejs-2de19af3/lib'026584d.lock for /usr/local/lib/node_modules/.staging
WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/sorted-object-b497dff3/lib'
WARN tar EISDIR: blah blah many more lines like this
WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/mkdirp-f65a1b18/test'

npm ERR! path /usr/local/lib/node_modules/express-generator/node_modules/mkdirp/bin/cmd.js
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall chmod
npm ERR! enoent ENOENT: no such file or directory, chmod '/usr/local/lib/node_modules/express-generator/node_modules/mkdirp/bin/cmd.js'
npm ERR! enoent This is …
Run Code Online (Sandbox Code Playgroud)

node.js npm express-generator npm-install

5
推荐指数
1
解决办法
642
查看次数

使用npm安装express-generator时出错

我尝试使用命令 npm installexpress-generator 安装express-generator,但出现以下错误。我在网上搜索并找不到任何有用的答案。

npm WARN deprecated mkdirp@0.5.1: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm ERR! Unexpected end of JSON input while parsing near '...DHZShvBYWKIIktsiBUuRD'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\ASUS\AppData\Roaming\npm-cache\_logs\2020-07-12T10_29_10_754Z-debug.log
Run Code Online (Sandbox Code Playgroud)

node.js npm express express-generator npm-install

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

我应该使用哪个命令来缩小和优化 nodejs express 应用程序?

我准备好使用 Express-generator sccafold 网站,需要发布它。我应该使用哪个命令来缩小文件并针对发布进行优化?而且,我应该上传哪些目录?

deployment express web express-generator

4
推荐指数
1
解决办法
1242
查看次数

“cd”有什么意义?在“cd .&& npm install”中?

我正在使用Express Generator。运行生成器后,它输出以下内容:

   install dependencies:
     $ cd . && npm install
Run Code Online (Sandbox Code Playgroud)

有什么意义cd .

node.js express express-generator

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

express --view=hbs myapp 获取 [ERR_INVALID_CALLBACK]:回调必须是函数

在此输入图像描述-express --view=hbs myapp [节点版本 12.18.2]

出现这样的错误

TypeError [ERR_INVALID_CALLBACK]: Callback must be a function

node.js express express-generator

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

将 socket.io 与 express 4 生成器一起使用

节点的新手,所以我很抱歉。我正在开发我的应用程序,我想使用 socket.io 发送位置。我找到了 1000 个例子,但都是指 express 没有路由的时候,而且都在 app.js 中。所有示例均指聊天应用程序。我能够运行一个示例,将我搜索的几个问题拼凑在一起,但是,我不明白如何让我最终在我的 app.js 上工作的 io 与我的 index.js 交互,以便我可以将它与多个发射一起使用参数。express.io 已过时,我找不到任何当前内容。在 bin/www

/**
 * Socket.io
 */
var io = app.io
io.attach( server );
Run Code Online (Sandbox Code Playgroud)

我的 app.js

var socket_io = require('socket.io');

var app = express();

var io = socket_io();
app.io = io;
Run Code Online (Sandbox Code Playgroud)

所以我可以使用:

io.on('connection', function (socket) {
    console.log('IO Ready');
});
Run Code Online (Sandbox Code Playgroud)

我不知道如何在我的 index.js(路由)上使用套接字,我无法对其进行模块化。

提前致谢。

javascript sockets node.js socket.io express-generator

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

安装没有全局属性的express-generator

我正在通过Dreamhost工作VPS,他们不允许使用,sudo所以我不能express-generator全局安装.我真的很喜欢在调用express命令时表达启动的所有文件.有没有一种方法可以在express-generator没有全局属性的情况下安装或者获取命令express初始化的所有文件的方法?

node.js express express-generator

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

Node/Express 4中间件无法正常工作

我有一个使用快速生成器生成的应用程序,带有bin/www文件和app.js文件.在app.js中,我添加了以下内容:

app.use(function(req, res, next){
      console.log("--------new middleware");
      next();
    });
Run Code Online (Sandbox Code Playgroud)

但它根本不是在调用中间件.该应用程序的其余部分工作正常,我已确认服务器正在运行并接收请求.

这是app.js:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var passport = require('passport');


var routes = require('./routes/index');
var users = require('./routes/users');
Run Code Online (Sandbox Code Playgroud)

//很多路线

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');

app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use(session({ secret: 'separation anxiety' }));
app.use(passport.initialize()); …
Run Code Online (Sandbox Code Playgroud)

middleware node.js express express-generator

-1
推荐指数
1
解决办法
1815
查看次数