- Express Development Environment Overview
- node and express make it every easy to set up your computer to start developing applications.
- This provides an overview of what tools are needed, explains some of the simplest methods for install Node and Express, and
- How to test your installation
- What is the express development environment?
- Express – installation of nodejs, npm, express application generator.
- Node and npm – installed together from binary packages.
- Express is then installed by NPM – dependency of individual Express
- NPM can also be used to install the Express Application Generator.
- This provides a MVC skeleton.
- Don’t need the application generator.
- Installing Node
- Install nodejs and NPM: https://nodejs.org/en/
- To test: node -v, npm -v
- See code in part one to test if it is working.
- Using NPM
- NPM is used to fetch an y packages that an application needs for development, testing and/or production
- Can also run tests.
- Can use NPM to fetch each needed package.
- Typically we use a definition file called package.json.
- Lists all the dependencies.
- Should contain everything NPM needs to fetch and run your application.
- Adding dependencies
- This is how you can use NPM to download a package, save it to the project dependences, then require it in a node application.
- See npm init to create a package.json file.
- Then we can look at the package.json file – defaults that you accepted, license,
- Can then install express- npm install express
- dependencies will be added – express for example.
- Development dependencies
- if we only want to use a dependency during development
- Save it as a development dependency
- npm install eslint —save-dev
- This will be added to the devDependencies section.
- Running Tasks
- Can define and fetch dependencies
- Can also define named scripts in your package.json files
- Call NPM to execute them with the run-script command.
- Commonly used to automate running tests/ parts of the development or build toolchain.
- Gulp and Grunt are task runners that do this too.
"scripts": {
...
"lint": "eslint src/js"
...
}
- Can now call this like this:
npm run-script lint
- OR (using the alias)
npm run lint
- Installing the Express Application Generator
- Express Application Generator – tool that generates an Express application “skeleton” .
- Install the generator using NPM:
npm install express-generator -g
npx express-generator helloworld
- Will create a new express app in a sub folder.
- The tool package.json file in its root directory.
- Then cd helloworld
- npm install
DEBUG=helloworld:* npm start
On to part 3.