Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Express.js?

I am a learner in Node.js.

  1. What's Express.js?
  2. What's the purpose of it with Node.js?
  3. Why do we actually need Express.js? How is it useful for us to use with Node.js?
  4. What's Redis? Does it come with Express.js?
like image 243
vinod Avatar asked Sep 27 '12 07:09

vinod


People also ask

What is express JS used for?

Express is a node js web application framework that provides broad features for building web and mobile applications. It is used to build a single page, multipage, and hybrid web application. It's a layer built on the top of the Node js that helps manage servers and routes.

What is the difference between NodeJS and Express?

NodeJS is an event-driven, non-blocking I/O model using JavaScript as its main language. It helps to build scalable network applications. Express is a minimal and flexible Node. js web application framework that provides a robust set of features for web and mobile applications.

Is Express JS is frontend or backend?

js, or simply Express, is a back end web application framework for Node. js, released as free and open-source software under the MIT License. It is designed for building web applications and APIs.

What is express JS in simple terms?

Express. js is a free and open-source web application framework for Node. js. It is used for designing and building web applications quickly and easily. Web applications are web apps that you can run on a web browser.


2 Answers

1) What is Express.js?

Express.js is a Node.js framework. It's the most popular framework as of now (the most starred on NPM).

Enter image description here.

It's built around configuration and granular simplicity of Connect middleware. Some people compare Express.js to Ruby Sinatra vs. the bulky and opinionated Ruby on Rails.

2) What is the purpose of it with Node.js?

That you don't have to repeat same code over and over again. Node.js is a low-level I/O mechanism which has an HTTP module. If you just use an HTTP module, a lot of work like parsing the payload, cookies, storing sessions (in memory or in Redis), selecting the right route pattern based on regular expressions will have to be re-implemented. With Express.js, it is just there for you to use.

3) Why do we actually need Express.js? How it is useful for us to use with Node.js?

The first answer should answer your question. If no, then try to write a small REST API server in plain Node.js (that is, using only core modules) and then in Express.js. The latter will take you 5-10x less time and lines of code.

What is Redis? Does it come with Express.js?

Redis is a fast persistent key-value storage. You can optionally use it for storing sessions with Express.js, but you don't need to. By default, Express.js has memory storage for sessions. Redis also can be use for queueing jobs, for example, email jobs.

Check out my tutorial on REST API server with Express.js.

MVC but not by itself

Express.js is not an model-view-controller framework by itself. You need to bring your own object-relational mapping libraries such as Mongoose for MongoDB, Sequelize (http://sequelizejs.com) for SQL databases, Waterline (https://github.com/balderdashy/waterline) for many databases into the stack.

Alternatives

Other Node.js frameworks to consider (https://www.quora.com/Node-js/Which-Node-js-framework-is-best-for-building-a-RESTful-API):

UPDATE: I put together this resource that aid people in choosing Node.js frameworks: http://nodeframework.com

UPDATE2: We added some GitHub stats to nodeframework.com so now you can compare the level of social proof (GitHub stars) for 30+ frameworks on one page.

enter image description here

Full-stack:

  • http://sailsjs.org

  • http://derbyjs.com/

Just REST API:

  • http://mcavage.github.io/node-restify/

Ruby on Rails like:

  • http://railwayjs.com/

  • http://geddyjs.org/

Sinatra like:

  • http://expressjs.com/

Other:

  • http://flatironjs.org/

  • https://github.com/isaacs/npm-www

  • http://frisbyjs.com/

Middleware:

  • http://www.senchalabs.org/connect/

Static site generators:

  • http://docpad.org

  • https://github.com/jnordberg/wintersmith

  • http://blacksmith.jit.su/

  • https://github.com/felixge/node-romulus

  • https://github.com/caolan/petrify

like image 97
10 revs, 7 users 71% Avatar answered Oct 22 '22 16:10

10 revs, 7 users 71%


This is over simplifying it, but Express.js is to Node.js what Ruby on Rails or Sinatra is to Ruby.

Express 3.x is a light-weight web application framework to help organize your web application into an MVC architecture on the server side. You can use a variety of choices for your templating language (like EJS, Jade, and Dust.js).

You can then use a database like MongoDB with Mongoose (for modeling) to provide a backend for your Node.js application. Express.js basically helps you manage everything, from routes, to handling requests and views.

Redis is a key/value store -- commonly used for sessions and caching in Node.js applications. You can do a lot more with it, but that's what I'm using it for. I use MongoDB for more complex relationships, like line-item <-> order <-> user relationships. There are modules (most notably connect-redis) that will work with Express.js. You will need to install the Redis database on your server.

Here is a link to the Express 3.x guide: https://expressjs.com/en/3x/api.html

like image 34
chovy Avatar answered Oct 22 '22 17:10

chovy