Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

express or express-generator: do i need both?

Just exploring node.js and came across express; On the npm repository site https://www.npmjs.com/package/express it clearly states installation is

$ npm install express

but if i scroll down the quick start mentions

$ npm install -g express-generator@4

Can someone explain in detail what is going on? I googled and understand in express v3 both were bundled together, but in express v4 the generator was pulled out.

So do i need to install both? does the generator install express automatically but not the other way around? I have JS fatigue already, and i only just started :-(

Supplementary Question: Then to confuse matters even further, i saw another question that asks should I start with 'npm init' and require express, or 'express myApp'. What is really going on now, where does init come into it?

Update 30/Jan/2017 I've accepted an answer below from someone else, but I've also added my own answer which is what i was seeking back then as a confused complete beginner. It may help others.

like image 519
joedotnot Avatar asked Dec 24 '16 07:12

joedotnot


People also ask

Do I need to use Express generator?

For learning Express, it's best to stick with the generator. Once you get a handle on how everything interacts and you feel comfortable making changes to the general structure, you could move onto other things or simply put together your own framework if you find yourself using the same general setup for projects.

What is Express generator used for?

Express Generator is a Node. js Framework like ExpressJS which is used to create express Applications easily and quickly. It acts as a tool for generating express applications.


1 Answers

My understanding is:

  • The express package is the framework that exposes functionalities you can use in your code
  • The express-generator package a utility that provides a command-line tool you can use to scaffold your project - ie create boilerplate folder structure, files and code.

As part of the boiler plate files is a package.json file defining the dependencies for your project - ie npm packages that you will need for your project. The express package is listed there.

Knowing the npm install instruction (run with current working directory set to project folder containing the package.json) will "install" all dependencies listed in package.json into your project folder to make them available to your application, it would be sufficient to do:

  • npm install express-generator -g
  • npm install
like image 196
IAmDranged Avatar answered Oct 29 '22 05:10

IAmDranged