What is the different between express and express-generator - node.js

As you might know, express released 4.1.0 recently. Now you can not use the command line "express" directly via npm intall -g express which is working just well in version 3.x. When I read the Readme in the package, I saw express-generator. After npm install -g express-generator, I can use the command line. So,what's the difference? Only for global install?

With express 4 the express boilerplate generator command line was extracted to it's own module 'express-generator' because the generator app did not really share code with express web framework and express and generator app can be released independently.
I guess this was a step into the right direction to decouple the web framework from the boilerplate/skeleton generator since this makes express even more lightweight and leverages tools like yeoman that focus on generating things.

The difference is that with Express 4, a lot of middleware and other things that were not necessary for "core" Express were exported into separate modules. The Express project generator happened to be one of those things.

Related

Loading Nodejs Module at runtime in electron app

Currently I am playing around with electron using vue-cli-plugin-electron-builder along side a simple vue project. This is the project https://github.com/nklayman/vue-cli-plugin-electron-builder .
vue create my-project
cd my-project
vue add electron-builder
npm run electron:serve
My goal is to add a simple plugin-like architecture. The app serves only base functionality but can be extended with "plugins". Those plugins therefore are not included in the built, but will be loaded at runtime by electron. I would prefere when those plugins just behave like node modules ( module.exports = ) with its own dependencies ( probably with a package.json file inside ). I would locate those plugins at app.getPath('userData') + '/Plugins.
I looked at a few approaches on how to tackle this problem :
1. Using Nodejs vm module
First, I tried using Nodejs vm module to read and execute a script from an external file, all at runtime. It works great so far, although I would not be able to use external dependencies inside those loaded scripts. If I want to use external dependencies inside the plugin scripts, those dependencies must have been included in the electron build beforehand. Somehow defeats the whole purpose of having plugins ... only vanilla js + nodejs base modules would be possible .
2. using global.require
I saw this solution in another SO answer.
Using node require with Electron and Webpack
Webpack/electron require dynamic module
They say to use global.require but it throws an error saying global.require is not a function. The solution looked promising first, but somehow I can't get it to work.
3. simply use require
Of course I had to try it. When I try to require an external module from a non-project location it won't find the module, even if the path is correct. Again, the path I am trying to locate the module should be at app.getPath("userData"), not in the projects root directory. When however, I locate the plugins inside the root directory of the project it gets included in the built. This again defeats the purpose of having plugins.
Goal
So far, I haven't found a viable solution to this. I simply want my electron app to be extendible with basic node modules at runtime ( following a pre-defined schema to simplify ) . Of course there is atom, made with electron, using their own apm manager to install and load plugins, but this seems way to overpowered. Its enough for me to only have plugin files located locally, to have a public "marketplace" is no goal. Also, it's ok if the app has to reload / restart to load plugins.
Any ideas ?
After more and more research I stumbled over 2 packages :
https://www.npmjs.com/package/live-plugin-manager
https://github.com/getstation/electron-package-manager
both integrating npm to programmatically handle package installation at runtime. I settled for live-plugin-manager for now since its better documented and even allow package installation from local file system.
Pro
I was able to integrate the system out-of-the-box into a vanilla electron app. Works like a charm.
Cons
.I was not able to use it inside a vue electron boilerplate (like the one I said I was using in OP), since webpack is interferring with the require environment. But there sure is a solution to this.
Update : I was able to get it to work eventually inside a webpack bundled electron vue boilerplate. I accidentally mixed import and require . The following code works for me using live-plugin-manager
// plugin-loader.js
const path = require('path');
const { PluginManager } = require('live-plugin-manager');
const pluginInstallFolder = path.resolve(app.getPath('userData'), '.plugins');
const pluginManager = new PluginManager();
module.exports = async (pkg) => {
// installs pkg from npm
await pluginManager.install(pkg);
const package = pluginManager.require(pkg);
return package
}
// main.js
const pluginLoader = require('./plugin-loader');
pluginLoader("moment").then((moment) => {
console.log(moment().format());
})
This will install "moment" package from npm during runtime into a local directory and load it into the app, without bundling it into the executable files.

How to integrate other ember app to existing project?

I am working on ember cli version 1.12 and node js version v0.12.7,I want to intergrate ember-cli-barcode addon.I have tried following:
ember install:npm ember-cli-barcode
Then it will show message that it required node version 4 >.So I have used Node version v7.0.0 stable.I installed node modules and addon.
Then tried following command:
npm install
bower install
ember server
But It will always shows errors,of node-modules etc.Kindly help me for the same how to integrate addon and which file need to change.
This should be a comment but I can't comment yet. I'm the author and it's compatible with Ember 2.4 onward. I will be putting version compatibility information in the readme.
I haven't worked with a cli version this old but ember install should be all you need if it's compatible. The add-on is a really thin wrapper around JsBarcode, so you could use the library direct if you have stay with the current ember version.
To get the benefits of the full ember-cli ecosystem, you'd have to be using the versions that support it. I think that it began in 1.13
As mentioned, it's highly likely that this addon assumes the standard CLI setup. You could ask the author.
Depending on your app complexity, you could do a few different things.
You could use the js library https://github.com/lindell/JsBarcode - (which is what the addon uses)
OR you may want to rewrite the app with the latest and greatest - now. 1.12 is going to be expensive to keep up / and since you've likely figured out how all the logic should work, then writing it again won't be the hardest part. (this sounds fun, right?) - and then use the addon
Which will take longer?

Meteor application hangs up after creating bundle

I am trying to run meteor app after deploying but it hangs up and never responds I have already set all the env varibales. Please help
node main.js
Note: you are using a pure-JavaScript implementation of bcrypt.
While this implementation will work correctly, it is known to be
approximately three times slower than the native implementation.
In order to use the native implementation instead, run
meteor npm install --save bcrypt
in the root directory of your application.
... no response

Adding supertest to Aurelia causes error when building vendor bundle

I have a current project using aurelia.
I add the supertest library using npm.
npm install supertest --save-dev
Now add package to aurelia.json file
{
"name": "supertest",
"path": "../node_modules/supertest"
}
Now run aurelia build
au run
produces following error:
Tracing supertest...
error /Users/xxxxxxx/node_modules/supertest.js
Writing app-bundle.js...
I have tried everything I can think of to fix this. Any help would be appreciated.
I recommend you to use the aurelia-skeleton-navigation setup instead which uses Gulp and JSPM -> https://github.com/aurelia/skeleton-navigation. This will provide you more on control on your project.
Aurelia CLI is still on alpha, quoting from https://github.com/aurelia/cli:
Note: The CLI is currently in Alpha and as such may not be suitable for use on all projects yet. In particular, projects that need to make use of extensive 3rd party libraries or Aurelia plugins may not yet work or may require extensive custom configuration or workarounds. We are in the process of addressing these issues.
Emphasis on extensive custom configuration or workarounds lol. I myself tried the CLI initially but ended up switching to Gulp and JSPM setup instead because of the tedious importing of external libraries.

Installing NodeAdmin for Node.JS on Ubuntu

I'm a seasoned developer in using the LAMP stack and am trying to switch over to Node.js and play around with it. For database management, I love the flexibility and ease of PHPmyadmin and found the NPM package NodeAdmin to be exactly what I"m looking for in terms of an analogue.
But when trying to install and access nodeadmin, the instructions look like complete Greek to me as someone coming from the Apache environment: https://www.npmjs.com/package/nodeadmin
I ran
npm install nodeadmin
inside the root directory and all looked good. But now I'm unable to access nodeadmin under mydomain.com/nodeadmin as it says I should in the instructions. What directory should I be installing nodeadmin in? What the heck do I do with the code in the "Setup" section of that tutorial?
Thanks in advance for helping break in a newb to his new environment.
Looks like nodeadmin is meant to be run as express middleware. The most basic set up would be to create a new file, let's call it app.js. The content of app.js should be:
var express = require('express');
var app = express();
var nodeadmin = require('nodeadmin');
app.use(nodeadmin(app)); //here is where you add the middleware
app.listen(80);
After that, go to directory where you created app.js and run the following commands
npm install express
npm install nodeadmin
node app.js
It looks like nodeadmin is express middleware, so you don't install it standalone. Instead you include the middleware in your website application and then access it via the same host on the /nodeadmin path.
I guess it uses the mysql config from your app to connect to the same db so you can use it to manage the application data.
var nodeadmin = require('nodeadmin');
app.use(nodeadmin(app));
express is a web framework for building nodejs apps. The nodeadmin module you're using can only be used as part of an express application. You'll need to use something else if you want to run it standalone.
A quick google turns up Express Admin. Looks like it's built using express, but doesn't need to be installed as part of an express app. You could give that a try. There may be better alternatives
I ended up getting more errors after following the above answers and am giving up and installing PHPmyadmin (which I realize I should have done from the beginning). Thanks for the answers.

Resources