我正在努力创建我的nodejs项目的可执行发行版。我想发送一个可执行文件,类似于嵌入了Tomcat的可执行jar。我读

Node Compiler is a command-line utility that compiles your Node.js application into a single executable file.


https://www.npmjs.com/package/node-compile

安装后抛出npm,我尝试:

nodejs my-project-nodejs # node-compiler server.js
....> ERROR: trying to use package.json variables, but not setup to do so!


因此,我的直截了当的问题是:我的package.json中缺少什么?

除此之外,我正在使用MongoDb。我相信,如果我的客户下载并isntall MongoDb开始执行可执行的nodejs项目,我将不会遇到问题。我正在评论它,因为我在相同的URL中阅读:

but by using default nexe, we could not easily produce a working binary which with with monogoose + express.js


据我了解,由于我尝试使用节点编译而不是纯nexe,因此MongoDb不会遇到问题。

server.js

// Load required packages
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var ejs = require('ejs');
var session = require('express-session');
var passport = require('passport');
var userController = require('./controllers/user');
var authController = require('./controllers/auth');
var oauth2Controller = require('./controllers/oauth2');
var clientController = require('./controllers/client');

var cartaoController = require('./controllers/cartao');


mongoose.connect('mongodb://localhost:27017/my-db');

// Create our Express application
var app = express();

// Set view engine to ejs
app.set('view engine', 'ejs');

// Use the body-parser package in our application
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: true
}));

// Use express session support since OAuth2orize requires it
app.use(session({
  secret: 'Super Secret Session Key',
  saveUninitialized: true,
  resave: true
}));

// Use the passport package in our application
app.use(passport.initialize());

// Create our Express router
var router = express.Router();

router.route('/cartoes')
.post(cartaoController.postCartoes);
 // .post(authController.isAuthenticated, cartaoController.postCartoes);

router.route('/users')
  .post(userController.postUsers)
  .get(authController.isAuthenticated, userController.getUsers);

router.route('/clients')
  .post(authController.isAuthenticated, clientController.postClients)
  .get(authController.isAuthenticated, clientController.getClients);

router.route('/oauth2/authorize')
  .get(authController.isAuthenticated, oauth2Controller.authorization)
  .post(authController.isAuthenticated, oauth2Controller.decision);

router.route('/oauth2/token')
  .post(authController.isClientAuthenticated, oauth2Controller.token);

app.use('/api', router);

app.listen(3000);


package.json

{
  "name": "my-app-dmz",
  "main": "server.js",
  "dependencies": {
    "bcrypt-nodejs": "0.0.3",
    "body-parser": "^1.0.2",
    "ejs": "^1.0.0",
    "express": "^4.1.1",
    "express-session": "^1.6.1",
    "mongoose": "^3.8.8",
    "node-rest-client": "^2.5.0",
    "oauth2orize": "^1.0.1",
    "passport": "^0.2.0",
    "passport-http": "^0.2.2",
    "passport-http-bearer": "^1.0.1",
    "reqclient": "^2.1.0"
  }
}


模型之一

// Load required packages
var mongoose = require('mongoose');

// Define our client schema
var ClientSchema = new mongoose.Schema({
  name: { type: String, unique: true, required: true },
  id: { type: String, required: true },
  secret: { type: String, required: true },
  userId: { type: String, required: true }
});

// Export the Mongoose model
module.exports = mongoose.model('Client', ClientSchema);

最佳答案

尝试将我的应用程序与nexe捆绑在一起时,刚刚得到相同的警告。

为了解决这个问题,我只需要在package.json文件中添加一个"nexe"条目,如nexe文档所建议的:
https://github.com/nexe/nexe/tree/V1-EOL#packagejson-inclusion

"nexe": {
    "input": "./bin/nexe",
    "output": "nexe^$",
    "temp": "src",
    "browserify": {
        "requires": [],
        "excludes": [],
        "paths": []
    },
    "runtime": {
        "framework": "node",
        "version": "5.6.0",
        "js-flags": "--use_strict",
        "ignoreFlags": true
    }
}

08-15 21:22