{"id":7578,"date":"2015-09-30T22:21:23","date_gmt":"2015-09-30T19:21:23","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=7578"},"modified":"2018-01-05T18:01:44","modified_gmt":"2018-01-05T16:01:44","slug":"node-js-express-tutorial","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/","title":{"rendered":"Node.js: Express tutorial"},"content":{"rendered":"<p><em>This article is part of our Academy Course titled <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-web-apps-with-node-js\">Building web apps with Node.js<\/a>.<\/em><\/p>\n<p>In this course, you will get introduced to Node.js. You will learn how to install, configure and run the server and how to load various modules.<\/p>\n<p>Additionally, you will build a sample application from scratch and also get your hands dirty with Node.js command line programming.<br \/>\nCheck it out <a href=\"http:\/\/www.webcodegeeks.com\/javascript\/node-js\/building-web-apps-with-node-js\">here<\/a>!<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n&nbsp;<br \/>\n[ulp id=&#8217;7Yp6ijpjjxyeaN8A&#8217;]<\/p>\n<div class=\"toc\">\n<h4>Table Of Contents<\/h4>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<\/dl>\n<p><a href=\"#express.js_installation\">2. Express.js Installation<\/a><a href=\"#express.js_objects\">3. Express.js Objects<\/a><\/p>\n<dl>\n<dt><a href=\"#application_object\">3.1. The application object<\/a><\/dt>\n<dt><a href=\"#request_object\">3.2. The request object<\/a><\/dt>\n<dt><a href=\"#response_object\">3.3. The response object<\/a><\/dt>\n<\/dl>\n<dl><\/dl>\n<p><a href=\"#concepts_in_express\">4. Concepts used in Express<\/a><\/p>\n<dl>\n<dt><a href=\"#asynchronous_js\">4.1. Asynchronous JavaScript<\/a><\/dt>\n<dt><a href=\"#middleware_node_apps\">4.2. Middlewares in node.js applications<\/a><\/dt>\n<\/dl>\n<dl><\/dl>\n<p><a href=\"#definition_routes\">5. Definition of Routes<\/a><\/p>\n<dl>\n<dt><a href=\"#handle_routes_in_express.js\">5.1. How to handle routes in express.js<\/a><\/dt>\n<dt><a href=\"#namespaced_routing\">5.2. Namespaced Routing<\/a><\/dt>\n<\/dl>\n<dl><\/dl>\n<p><a href=\"#http_response_express\">6. HTTP response in Express<\/a><\/p>\n<dl>\n<dt><a href=\"#set_http_statusCode\">6.1. Setting the HTTP status code<\/a><\/dt>\n<dt><a href=\"#set_http_headers\">6.2. Setting HTTP headers<\/a><\/dt>\n<dt><a href=\"#send_data\">6.3. Sending data<\/a><\/dt>\n<\/dl>\n<dl><\/dl>\n<p><a href=\"#webApp_with_NeDB\">7. Sample web application with NeDB<\/a><\/p>\n<dl>\n<dt><a href=\"#installation\">7.1. Installation<\/a><\/dt>\n<dt><a href=\"#configuration_code\">7.2. Configuration Code<\/a><\/dt>\n<dt><a href=\"#router_handling_code\">7.3. Router Handling Code<\/a><\/dt>\n<dt><a href=\"#angular.js_part\">7.4. Angular.js part<\/a><\/dt>\n<dt><a href=\"#angular_template_html\">7.5. Angular Template and HTML<\/a><\/dt>\n<\/dl>\n<dl><\/dl>\n<p><a href=\"#download\">8. Download the Source Code<\/a><\/p>\n<p>&nbsp;<\/p>\n<\/div>\n<h2><a name=\"introduction\"><\/a>1. Introduction<\/h2>\n<p>Express.js is a powerful web development framework for the Node.js (Node) platform. Express.js comes with the rest of the Node.js middleware modules. These modules are JavaScript components which can be used in Node.js based web applications to make the application layered and more modular.<\/p>\n<p>With express.js, except for the express.js APIs, other node.js core APIs can also be called. The Express.js framework can be used in order to develop any kind of web application, from simple to complex ones. As always, when developing with Node.js , we have to keep in mind the asynchronous behaviour of our application.<\/p>\n<h2><a name=\"express.js_installation\"><\/a>2. Express.js Installation<\/h2>\n<p>After <a href=\"http:\/\/www.webcodegeeks.com\/2015\/09\/node-js-installation-tutorial\/\">installing Node.js<\/a> in our machine, it is easy to also install express.js. This is accomplished via the node.js package manager. We need to install express.js as a node module with the -g option as an npm install command at terminal.<\/p>\n<p>The command to install Express is the following:<\/p>\n<pre class=\"brush:bash\">$ sudo npm install express -g\r\n<\/pre>\n<p>This will install the latest stable version of Express.<\/p>\n<p>If we need to install express.js locally, then we need to run the following:<\/p>\n<pre class=\"brush:bash\">$ sudo npm install express\r\n<\/pre>\n<p>The difference between local and global installation is this: for local installation, the express.js will be available in the <code>node_modules<\/code> folder within the express.js folder, while for the global installation, the express.js will be available at the node executable path for all the applications which are developed on the particular machine.<\/p>\n<p>The express.js installation can be confirmed by requesting the version for express.js. Run the following in the terminal:<\/p>\n<pre class=\"brush:bash\">$ express \u2013V\r\n&gt; 3.4.7\r\n<\/pre>\n<h2><a name=\"express.js_objects\"><\/a>3. Express.js Objects<\/h2>\n<h3><a name=\"application_object\"><\/a>3.1. The application object<\/h3>\n<p>The application object is an instance of Express, generally presented by the variable named &#8216;app&#8217;. This is the main object of our Express applocation and all functionality is built on top of that object.<\/p>\n<p>Creating an instance of the Express.js module within the node application is done as follows:<\/p>\n<pre class=\"brush:js\">var express = require('express');\r\nvar app = new express();\r\n<\/pre>\n<h3><a name=\"request_object\"><\/a>3.2. The request object<\/h3>\n<p>Now, when a web client makes a request to the Express application, the HTTP request object is created. Inside all the application callbacks, whenever the request objects are passed as reference, those are represented with the conventional variable <code>req<\/code>. This request object holds all the HTTP stack related variables, such as headers information, HTTP methods and related properties for that particular request from the web client.<\/p>\n<p>Let&#8217;s see the most important methods of Request object:<\/p>\n<ol>\n<li><em>req.params<\/em>: Holds the values of all the parameters of the request object.<\/li>\n<li><em>req.params(name)<\/em>: Returns value of a specific parameter from the Web URL GET params or POST params.<\/li>\n<li><em>req.query<\/em>: Takes values from a GET method submission.<\/li>\n<li><em>req.body<\/em>: Takes values from a POST form submission.<\/li>\n<li><em>req.get(header)<\/em>: Gets the request HTTP header.<\/li>\n<li><em>req.path<\/em>: The request path.<\/li>\n<li><em>req.url<\/em>: The request path with query parameters.<\/li>\n<\/ol>\n<h3><a name=\"response_object\"><\/a>3.3. The response object<\/h3>\n<p>The response object is created along with the request object, and is generally represented by a variable named <code>res<\/code>. In the HTTP Request-Response model, all the express middlewares work on the request and the response objects while one is passing the control after another.<\/p>\n<p>Let&#8217;s see the most important methods of Response object:<\/p>\n<ol>\n<li><em>res.status(code)<\/em>: The HTTP response code.<\/li>\n<li><em>res.attachment([filename])<\/em>: The response HTTP header Content-Disposition to attachment.<\/li>\n<li><em>res.sendfile(path, [options], Sends a file to the client [callback])<\/em>.<\/li>\n<li><em>res.download(path, [filename], Prompts the client to download from [callback])<\/em>.<\/li>\n<li><em>res.render(view, [locals], Renders a view callback)<\/em>.<\/li>\n<\/ol>\n<h2><a name=\"concepts_in_express\"><\/a>4. Concepts used in Express<\/h2>\n<h3><a name=\"asynchronous_js\"><\/a>4.1. Asynchronous JavaScript<\/h3>\n<p>Node.js programming is mainly based on Asynchronous Javascript Programming. All of the modules in node.js are built asynchronous in nature. So, the execution of the code from one layer to another generally is performed within callback functions.<\/p>\n<p>As node.js program executes in an event loop, the end user generally does not face any &#8220;blocking&#8221; from the view layer, i.e. the web browser or mobile browser etc. Generally the callback function is passed as an async function to be executed. This function will return the result to the upper function when the execution of code is completed.<\/p>\n<p>Note that all the programs within express.js and the associated programs are installed in the node.js environment as node modules. For any node.js application, the deployment configuration is written in a &#8220;package.json&#8221; file. If we need to install the application as a node module in the node.js environment, i.e. through the npm install command, we should also include the package.json file.<\/p>\n<h3><a name=\"middleware_node_apps\"><\/a>4.2. Middlewares in node.js applications<\/h3>\n<p>A middleware in a node.js application context is a JavaScript function which will handle HTTP requests. It will be able to handle the request and the response objects from HTTP request, perform some operation on the request, send back the response to the client and finally pass the objects\/results to the next middleware. Middlewares are loaded in an Express application with the app.use() method.<\/p>\n<p>A basic example of a middleware is oe that will handle a GET request method, as follows:<\/p>\n<pre class=\"brush:js\">app.use(function(req, res, next) {\r\n\tconsole.log('Request Query : ' + req.query);\r\n\tnext();\r\n});\r\n<\/pre>\n<p>This will print the &#8220;querystring&#8221; within the request object.<\/p>\n<p>The majority of the Express.js functionality is implemented with its built-in middlewares. One of the Express.js middleware is the router middleware, which is responsible for routing the HTTP requests inside Express applications to the appropriate data handler functions. From a user perspective, it is the navigational functionality in a web application.<\/p>\n<p>The destinations of the HTTP request URIs are defined via routes in the application. Routes are the controlling points for the response from a request, i.e they decide where to dispatch a specific request by analysing data carried on the request object. In traditional web applications, like a JEE Application, this functionality is handled by the Controller in the application. Route handlers may be defined in the app.js file or loaded as Node modules.<\/p>\n<p>Defining the routes and their handlers in the app.js file works fine when the number of routes is relatively small.<\/p>\n<p>The following code presents an example of routes.js in the Node module:<\/p>\n<pre class=\"brush:js\">module.exports = function(app) {\r\n\tapp.get('\/', function(req, res) {\r\n\t\t\/\/ Send a plain text response\r\n\t\tres.send('First Express Application!');\r\n\t});\r\n\r\n\tapp.get('\/hello.text', function(req, res) {\r\n\t\t\/\/ Send a plain text response\r\n\t\tres.send('Hello!');\r\n\t});\r\n\r\n\tapp.get('\/contact', function(req, res) {\r\n\t\t\/\/ Render a view named contact\r\n\t\tres.render('contact');\r\n\t});\r\n};\r\n<\/pre>\n<p>The app.js file can be defined as below:<\/p>\n<pre class=\"brush:js\">var http = require('http');\r\nvar express = require('express');\r\nvar app = express();\r\nvar routes = require('.\/routes')(app);\r\nhttp.createServer(app).listen(3000, function(){\r\n\t\tconsole.log('Express server listening on port ' + 3000);\r\n});\r\n<\/pre>\n<p>A request handler can send a response back to the client using response methods in the response object.<\/p>\n<h2><a name=\"definition_routes\"><\/a>5. Definition of Routes<\/h2>\n<p>Generally, a URL (Uniform Resource Locator) combines the HTTP request method (GET or POST) and the path pattern for a web application. The routes handle the URL with the appropiate route handler, which executes the job for any particular action for that URL. A request to the server that matches a route definition is routed to the associated route handler. The route handlers are also able to send the HTTP response or pass the request to the next middleware, if necessary.<\/p>\n<p>Routes in Express are defined using methods named as the HTTP methods, for example app.get(), app.post(), app.put() and so on.<\/p>\n<p>There is also another set of string-based route identifiers, which are used in order to specify placeholders for the request path.<\/p>\n<p>The following example demonstrates this concept:<\/p>\n<pre class=\"brush:js\">app.get('\/user\/:id', function(req, res) {\r\n\tres.send('user id: ' + req.params.id);\r\n});\r\napp.get('\/country\/:country\/state\/:state\/city\/:city', function(req, res) {\r\n\tres.send(req.params.country + ', ' + req.params.state + ', ' + req.params.city);\r\n}\r\n<\/pre>\n<p>So, the value of the placeholder name will be available in the req.params object which we can access as in the above example.<\/p>\n<p>Below is a code snippet for an optional parameter:<\/p>\n<pre class=\"brush:js\">app.get('\/feed\/:datatype?', function(req, res) {\r\n\tif (req.params.datatype) { res.send('Data Type: ' + req.params.datatype); }\r\n\telse { res.send('Text Data'); }\r\n});\r\n<\/pre>\n<h3><a name=\"handle_routes_in_express.js\"><\/a>5.1. How to handle routes in express.js<\/h3>\n<p>When a request is made to the server, for the given route definition, the associated callback function will be executed in order to process the request and send back the response. These callback functions generally define the behaviour of our application.<\/p>\n<h3><a name=\"namespaced_routing\"><\/a>5.2. Namespaced Routing<\/h3>\n<p>We can define the routes on the basis of a namespace, which will act as the root path and then the rest of the routes will be defined relatively to that route. By default, express.js does not have the capability for namespaced routing. For getting the advantage of this functionality, we will have to install the &#8216;express-namespace&#8217; node module.<\/p>\n<p>The command for the installation is the following:<\/p>\n<pre class=\"brush:bash\">$ npm install express-namespace\r\n<\/pre>\n<p>So now we can write the app.js as follows:<\/p>\n<pre class=\"brush:js\">var http = require('http');\r\nvar express = require('express');\r\n\/\/ express-namespace should be loaded before app is instantiated\r\nvar namespace = require('express-namespace');\r\nvar app = express();\r\n\r\napp.use(app.router);\r\napp.namespace('\/posts', function() {\r\n\tapp.get('\/', function(req, res) {\r\n\t\tres.send('all posts');\r\n\t});\r\n\tapp.get('\/new', function(req, res) {\r\n\t\tres.send('new post');\r\n\t});\r\n\tapp.get('\/edit\/:id', function(req, res) {\r\n\t\tres.send('edit post ' + req.params.id);\r\n\t});\r\n\tapp.get('\/delete\/:id', function(req, res) {\r\n\t\tres.send('delete post ' + req.params.id);\r\n\t});\r\n\tapp.get('\/2013', function(req, res) {\r\n\t\tres.send('articles from 2014');\r\n\t});\r\n\t\/\/ Namespaces can be nested\r\n\tapp.namespace('\/2014\/jan', function() {\r\n\t\t\tapp.get('\/', function(req, res) {\r\n\t\t\t\tres.send('posts from jan 2014');\r\n\t\t\t});\r\n\t\t\tapp.get('\/angularjs', function(req, res) {\r\n\t\t\t\tres.send('articles about Angular.js from jan 2014');\r\n\t\t\t});\r\n\t\t});\r\n\t});\r\n\thttp.createServer(app).listen(3000, function() {\r\n\t\tconsole.log('App started');\r\n\t});\r\n<\/pre>\n<p>We can see the results for the following urls:<\/p>\n<pre class=\"brush:js\"> http:\/\/localhost:3000\/posts\/\r\n http:\/\/localhost:3000\/posts\/edit\/1\r\n http:\/\/localhost:3000\/posts\/delete\/1\r\n http:\/\/localhost:3000\/posts\/2014\r\n http:\/\/localhost:3000\/posts\/2014\/jan\r\n http:\/\/localhost:3000\/posts\/2014\/jan\/angularjs\r\n<\/pre>\n<h2><a name=\"http_response_express\"><\/a>6. HTTP response in Express<\/h2>\n<p>A response from express.js can be generated with a minimal route and a callback as below:<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.send('our application response');\r\n});\r\n<\/pre>\n<p>Express.js can handle any type of Error in Application which are standard HTTP response error codes.<\/p>\n<h3><a name=\"set_http_statusCode\"><\/a>6.1. Setting the HTTP status code<\/h3>\n<p>We can set the HTTP status code by passing the number to the res.status() method.<\/p>\n<p>An example for sending the 404 Status code can be found below:<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\t\/\/ Set the status\r\n\tres.status(404);\r\n\t\/\/ Specify the body\r\n\tres.send('404 Error');\r\n});\r\n<\/pre>\n<p>By default, express.js sends response code 200.<\/p>\n<p>Also we can send the status as a chained response:<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\t\/\/ Status and body in one line\r\n\tres.status(404).send('resource not found');\r\n});\r\n<\/pre>\n<p>Some HTTP methods, like res.send(), res.json(), and res.jsonp() are capable of sending the HTTP status code themselves.<\/p>\n<p>In case of sending a 200 status code:<\/p>\n<p>The example is for res.send():<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.send('welcome');\r\n});\r\n<\/pre>\n<p>Now if a number is passed in the body, it will be like:<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.send(404);\r\n});\r\n<\/pre>\n<p>or<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.send(404, 'not found');\r\n});\r\n<\/pre>\n<h3><a name=\"set_http_headers\"><\/a>6.2. Setting HTTP headers<\/h3>\n<p>Express provides an interface for setting HTTP headers in the response message. We have to pass two parameters to the res.set() method; the first parameter is the header name and the second parameter is the value of the parameter.<\/p>\n<p>An example for setting the standard HTTP header with custom header variables is the following:<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.status(200);\r\n\tres.set('Content-Type', 'text\/plain; charset=us-ascii');\r\n\tres.set('X-Custom-Message', 'it is a custom message');\r\n\tres.send('HTTP header setting example');\r\n});\r\n<\/pre>\n<h3><a name=\"send_data\"><\/a>6.3. Sending data<\/h3>\n<p>If we want to serve plain text with the response, we can write:<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.send('&lt;\/pre&gt;\r\n&lt;h1&gt;Plain text&lt;\/h1&gt;\r\n&lt;pre&gt;\r\n');\r\n});\r\n<\/pre>\n<p>It will show <code>&lt;h1&gt;Plain text&lt;\/h1&gt;<\/code> in browser.<\/p>\n<p>Equivalent to this will be:<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.set('Content-Type', 'text\/plain');\r\n\tres.send('&lt;\/pre&gt;\r\n&lt;h1&gt;Plain text&lt;\/h1&gt;\r\n&lt;pre&gt;\r\n');\r\n});\r\n<\/pre>\n<p>If we want to see the HTML Equivalent of this, then we should try:<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.set('Content-Type', 'text\/html');\r\n\tres.send('&lt;\/pre&gt;\r\n&lt;h1&gt;Plain text&lt;\/h1&gt;\r\n&lt;pre&gt;\r\n');\r\n});\r\n<\/pre>\n<p>If we want json as output, we can do this by setting the json object in response i.e. by using the res.json method.<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.json({message: 'This is example of json'});\r\n});\r\n<\/pre>\n<p>It will set a default 200 HTTP Status with the response.<\/p>\n<p>For responding with content negotiation, the response object will return like the following with res.format method:<\/p>\n<pre class=\"brush:js\">app.get('\/', function(req, res) {\r\n\tres.format({\r\n\t\t'text\/plain': function() {\r\n\t\t\tres.send('Plain text');\r\n\t\t},\r\n\t\t'text\/html': function() {\r\n\t\t\tres.send('&lt;b&gt;welcome&lt;\/b&gt;');\r\n\t\t},\r\n\t\t'application\/json': function() {\r\n\t\t\tres.json({ message: 'welcome' });\r\n\t\t},\r\n\t\t'default': function() {\r\n\t\t\tres.send(406, 'Not Acceptable');\r\n\t\t}\r\n\t});\r\n});\r\n<\/pre>\n<p>The server will respond based on the data type mentioned in the HTTP Accept header.<\/p>\n<p>Now we will try to make a complete node.js application where the GET and POST methods are used from Express.js and will see how all these are tied together.<\/p>\n<h2><a name=\"webApp_with_NeDB\"><\/a>7. Sample web application with NeDB<\/h2>\n<p>We have chosen nedb for our datastore to make the application simple for reader. NeDB is a javascript based Embedded database. According to <a href=\"https:\/\/github.com\/louischatriot\/nedb\" target=\"_blank\">this<\/a>, NeDB is an<br \/>\n<em>&#8220;Embedded persistent database for Node.js, written in Javascript, with no dependency (except npm modules of course).&#8221;<\/em><\/p>\n<p>To make the application, we have selected:<\/p>\n<ol>\n<li>Angular.js for client side development \u2013 Single Page Application.<\/li>\n<li>Cross Domain Communication in between Angular.js and Node.js.<\/li>\n<li>Node.js for server side development.<\/li>\n<li>Rest based web service creation with express.js.<\/li>\n<li>Database \u2013 NeDb.<\/li>\n<li>Node.js NeDB Module Extention.<\/li>\n<\/ol>\n<p>We have created a Proof of Concept with a Javascript based web server, where we utilized NeDB with the javascript based framework Node.js and angular.js on the client side.<\/p>\n<p>The architecture at a glance:<\/p>\n<figure style=\"width: 784px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/Angular.js-Node-NeDB.png\"><img decoding=\"async\" class=\" alt=\" src=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/Angular.js-Node-NeDB.png\" alt=\"\" width=\"784\" height=\"506\" \/><\/a><figcaption class=\"wp-caption-text\">Figure 1<\/figcaption><\/figure>\n<p>Here are the steps:<\/p>\n<h3><a name=\"installation\"><\/a>7.1. Installation<\/h3>\n<ol>\n<li>Download and install Node.js as described <a href=\"http:\/\/www.webcodegeeks.com\/2015\/09\/node-js-installation-tutorial\/\">here<\/a>.<\/li>\n<li>To Develop the application we need to install nedb module for Node.js.\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nnpm install nedb\r\n<\/pre>\n<\/li>\n<li>We need to install express.js for node.js.\n<pre class=\"brush: java; title: ; notranslate\" title=\"\">\r\nnpm install express\r\n<\/pre>\n<\/li>\n<\/ol>\n<h3><a name=\"configuration_code\"><\/a>7.2. Configuration Code<\/h3>\n<p>Now, we will try to describe the used code portion:<\/p>\n<pre class=\"brush:js\">var application_root = __dirname,\r\n    express = require(\"express\"),\r\n    path = require(\"path\");\r\n<\/pre>\n<p>Here we have initialised the express.js based on the Node.js concepts discussed above.<\/p>\n<pre class=\"brush:js\">var app = express();\r\n<\/pre>\n<p>Here we have initialised the express web server and reference the app variable.<\/p>\n<pre class=\"brush:js\">var databaseUrl = \"\/home\/sampleuser\/nedb\/user.db\";\r\nvar Datastore = require('nedb');\r\ndb = {};\r\ndb.users = new Datastore({ filename: databaseUrl, autoload: true }); \/\/ to autoload datastore\r\n<\/pre>\n<p>Here we have made the connection to the nedb database using the Node.js nedb module extension library.<\/p>\n<pre class=\"brush:js\">\/\/ Config\r\n\r\napp.configure(function () {\r\n  app.use(express.bodyParser());\r\n  app.use(express.methodOverride());\r\n  app.use(app.router);\r\n  app.use(express.static(path.join(application_root, \"public\")));\r\n  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));\r\n});\r\n<\/pre>\n<p>Here we have made the configuration related to express.js.<\/p>\n<h3><a name=\"router_handling_code\"><\/a>7.3. Router Handling Code<\/h3>\n<pre class=\"brush:js\">app.get('\/api', function (req, res) {\r\n  res.send('Our Sample API is up...');\r\n});\r\n<\/pre>\n<p>Here we have made our first REST based web service and tested whether the express.js is up.<\/p>\n<p>Our sample api will be: http:\/\/127.0.0.1:1212\/api (GET Method).<\/p>\n<pre class=\"brush:js\">app.get('\/getangularusers', function (req, res) {\r\n\tres.header(\"Access-Control-Allow-Origin\", \"http:\/\/localhost\");\r\n\tres.header(\"Access-Control-Allow-Methods\", \"GET, POST\");\r\n        \/\/ The above 2 lines are required for Cross Domain Communication(Allowing the methods that will come as Cross Domain Request\r\n\t\/\/ More on this in later part of the code\r\n\tdb.users.find('', function(err, users) { \/\/ Query in NeDB via NeDB Module\r\n\tif( err || !users) console.log(\"No users found\");\r\n\t  else\r\n\t{\r\n\t\tres.writeHead(200, {'Content-Type': 'application\/json'}); \/\/ Sending data via json\r\n\t\tstr='[';\r\n\t\tusers.forEach( function(user) {\r\n\t\t\tstr = str + '{ \"name\" : \"' + user.username + '\"},' +'\\\\n';\r\n\t\t});\r\n\t\tstr = str.trim();\r\n\t\tstr = str.substring(0,str.length-1);\r\n\t\tstr = str + ']';\r\n\t\tres.end( str);\r\n                \/\/ Prepared the jSon Array here\r\n\t}\r\n  });\r\n});\r\n<\/pre>\n<p>Here we have created another REST API to get all usernames from a user collection and so we have performed the necessary NeDB query.<\/p>\n<p>Our sample api will be: http:\/\/127.0.0.1:1212\/getangularusers (GET Method).<\/p>\n<pre class=\"brush:js\">app.post('\/insertangularneuser', function (req, res){\r\n  console.log(\"POST: \");\r\n  res.header(\"Access-Control-Allow-Origin\", \"http:\/\/localhost\");\r\n  res.header(\"Access-Control-Allow-Methods\", \"GET, POST\");\r\n  \/\/ The above 2 lines are required for Cross Domain Communication(Allowing the methods that come as Cross\r\n  \/\/ Domain Request\r\n  console.log(req.body);\r\n  console.log(req.body.mydata);\r\n  var jsonData = JSON.parse(req.body.mydata);\r\n\r\n  db.users.save({email: jsonData.email, password: jsonData.password, username: jsonData.username},\r\n       function(err, saved) { \/\/ Query in NeDB via NeDB Module\r\n           if( err || !saved ) res.end( \"User not saved\");\r\n           else res.end( \"User saved\");\r\n       });\r\n});\r\n<\/pre>\n<p>Here we have made a POST request to create a user via a REST invocation.<\/p>\n<p>Our sample api will be: http:\/\/127.0.0.1:1212\/insertangularneuser (Post Method).<\/p>\n<pre class=\"brush:js\">\/\/ Launch server\r\napp.listen(1212);\r\n<\/pre>\n<p>We have made the server to listen at 1212 port.<\/p>\n<p>Now we can run node appnedbangular.js from command prompt\/terminal.<\/p>\n<h3><a name=\"angular.js_part\"><\/a>7.4. Angular.js part<\/h3>\n<p>We have used Angular.js for our client side work and development. We have made the choice of Angular.js as our front-end development tool as this maintains a clear client-side Model-View-Presenter Architecture and makes the code more structured.<\/p>\n<p>Since this part of the tutorial mainly concentrates on node.js and express.js, the reader is urged to acquire more knowledge about Angular.js <a href=\"http:\/\/docs.angularjs.org\/tutorial\" target=\"_blank\">here<\/a>.<\/p>\n<p>We provide inline doucmentation with our code to help you better understand the application with Angular.js<\/p>\n<p>So, below is the code for the <code>Angular Controller<\/code>.<\/p>\n<pre class=\"brush:js\">'use strict';\r\n\r\nvar myApp = angular.module('myApp', []); \/\/ Taking Angular Application in Javascript Variable\r\n\r\n\/\/ Below is the code to allow cross domain request from web server through angular.js\r\nmyApp.config(['$httpProvider', function($httpProvider) {\r\n        $httpProvider.defaults.useXDomain = true;\r\n        delete $httpProvider.defaults.headers.common['X-Requested-With'];\r\n    }\r\n]);\r\n\r\n\/* Controllers *\/\r\n\r\nfunction UserListCtrl($scope, $http, $templateCache) {\r\n\r\n  var method = 'POST';\r\n  var inserturl = 'http:\/\/localhost:1212\/insertangularneuser';\/\/ URL where the Node.js server is running\r\n  $scope.codeStatus = \"\";\r\n  $scope.save = function() {\r\n    \/\/ Preparing the Json Data from the Angular Model to send in the Server.\r\n    var formData = {\r\n      'username' : this.username,\r\n      'password' : this.password,\r\n\t  'email' : this.email\r\n    };\r\n\r\n\tthis.username = '';\r\n\tthis.password = '';\r\n\tthis.email = '';\r\n\r\n\tvar jdata = 'mydata='+JSON.stringify(formData); \/\/ The data is to be string.\r\n\r\n\t$http({ \/\/ Accessing the Angular $http Service to send data via REST Communication to Node Server.\r\n            method: method,\r\n            url: inserturl,\r\n            data:  jdata ,\r\n            headers: {'Content-Type': 'application\/x-www-form-urlencoded'},\r\n            cache: $templateCache\r\n        }).\r\n        success(function(response) {\r\n\t\tconsole.log(\"success\"); \/\/ Getting Success Response in Callback\r\n                $scope.codeStatus = response.data;\r\n\t\tconsole.log($scope.codeStatus);\r\n\r\n        }).\r\n        error(function(response) {\r\n\t\tconsole.log(\"error\"); \/\/ Getting Error Response in Callback\r\n                $scope.codeStatus = response || \"Request failed\";\r\n\t\tconsole.log($scope.codeStatus);\r\n        });\r\n\t$scope.list();\/\/ Calling the list function in Angular Controller to show all current data in HTML\r\n        return false;\r\n  };\t\r\n\r\n  $scope.list = function() {\r\n\t  var url = 'http:\/\/localhost:1212\/getangularusers';\/\/ URL where the Node.js server is running\r\n\t  $http.get(url).success(function(data) {\r\n\t\t$scope.users = data;\r\n\t  });\r\n          \/\/ Accessing the Angular $http Service to get data via REST Communication from Node Server\r\n  };\r\n\r\n  $scope.list();\r\n}\r\n<\/pre>\n<h3><a name=\"angular_template_html\"><\/a>7.5. Angular Template and HTML<\/h3>\n<pre class=\"brush:js\">&lt;html lang=\"en\" ng-app=\"myApp\"&gt;\r\n.....<\/pre>\n<p>We refer to the Angular Application in above code.<\/p>\n<pre class=\"brush:js\">&lt;body ng-controller=\"UserListCtrl\"&gt;\r\n.....\r\n<\/pre>\n<p>We refer to the Angular Controller in above code.<\/p>\n<p><em>Search:<\/em><\/p>\n<pre class=\"brush:css\">&lt;input ng-model=\"user\"&gt;\r\n&lt;div class=\"span10\"&gt;\r\n    &lt;!--Body content--&gt;\r\n    &lt;ul class=\"users\"&gt;\r\n        &lt;li ng-repeat=\"user in users | filter:user \"&gt;\r\n            {{user.name}}\r\n        &lt;\/li&gt;\r\n    &lt;\/ul&gt;\r\n&lt;\/div&gt;\r\n<\/pre>\n<p>We have used the ng-repeat tag to take the users data model from the REST invocation.<\/p>\n<pre class=\"brush:css\">&lt;form name=\"myform\" id=\"myform1\" ng-submit=\"save()\"&gt;\r\n    &lt;fieldset&gt;\r\n        &lt;legend&gt;New User&lt;\/legend&gt;\r\n            &lt;div class=\"control-group\"&gt;\r\n                &lt;center&gt;&lt;input type=\"text\" placeholder=\"User\u2026\" ng-model=\"username\" size=50 required\/&gt;&lt;\/center&gt;\r\n                &lt;center&gt;&lt;input type=\"text\" placeholder=\"Password\u2026\" ng-model=\"password\" size=50 required\/&gt;&lt;\/center&gt;\r\n                &lt;center&gt;&lt;input type=\"text\" placeholder=\"Email\u2026\" ng-model=\"email\" size=50 required\/&gt;&lt;\/center&gt;\r\n            &lt;\/div&gt;\r\n    &lt;\/fieldset&gt;\r\n    &lt;p&gt;\r\n         &lt;div&gt;&lt;center&gt;&lt;button type=\"submit\" &gt;Save now...&lt;\/button&gt;&lt;\/center&gt;&lt;\/div&gt;\r\n    &lt;\/p&gt;\r\n&lt;\/form&gt;\r\n<\/pre>\n<p>We have used the ng-submit tag to send the user data model from the REST invocation and send to the node server in order to persist it in the NeDB database.<\/p>\n<p>Please note that NeDB is just a light-weight Database which can be embedded in Node WebKit Applications. For fairly large scale database production systems, we should consider MongoDB.<\/p>\n<h2><a name=\"download\"><\/a>8. Download the Source Code<\/h2>\n<p>This tutorial discussed Express.js and how to use it along with Node.js. You may download the source code here: <a href=\"http:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2015\/09\/Node.js-NeDB.zip\">Node.js-NeDB.zip<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how to install, configure and run the server and how to load various modules. Additionally, you will build a sample application from scratch and also get your hands dirty &hellip;<\/p>\n","protected":false},"author":18,"featured_media":924,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-7578","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-node-js"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Node.js: Express tutorial - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Node.js: Express tutorial - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/phlocblogger\" \/>\n<meta property=\"article:published_time\" content=\"2015-09-30T19:21:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-01-05T16:01:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Piyas De\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/phloxblog\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Piyas De\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"19 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/\"},\"author\":{\"name\":\"Piyas De\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/7aab6e040a06f0dfe0d60c27768aa424\"},\"headline\":\"Node.js: Express tutorial\",\"datePublished\":\"2015-09-30T19:21:23+00:00\",\"dateModified\":\"2018-01-05T16:01:44+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/\"},\"wordCount\":2405,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"articleSection\":[\"Node.js\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/\",\"name\":\"Node.js: Express tutorial - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"datePublished\":\"2015-09-30T19:21:23+00:00\",\"dateModified\":\"2018-01-05T16:01:44+00:00\",\"description\":\"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Node.js\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Node.js: Express tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/7aab6e040a06f0dfe0d60c27768aa424\",\"name\":\"Piyas De\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/eadd6728b7b5be23f0d6585da1a953926e49c6f2369703d6cb4f1147d4dd2203?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/eadd6728b7b5be23f0d6585da1a953926e49c6f2369703d6cb4f1147d4dd2203?s=96&d=mm&r=g\",\"caption\":\"Piyas De\"},\"description\":\"Piyas is Sun Microsystems certified Enterprise Architect with 10+ years of professional IT experience in various areas such as Architecture Definition, Define Enterprise Application, Client-server\/e-business solutions.Currently he is engaged in providing solutions for digital asset management in media companies.He is also founder and main author of \\\"Technical Blogs (Blog about small technical Know hows)\\\"\",\"sameAs\":[\"http:\/\/www.phloxblog.in\",\"http:\/\/www.facebook.com\/phlocblogger\",\"http:\/\/in.linkedin.com\/in\/piyasde\",\"https:\/\/x.com\/https:\/\/twitter.com\/phloxblog\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/piyas-de\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Node.js: Express tutorial - Web Code Geeks - 2026","description":"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Node.js: Express tutorial - Web Code Geeks - 2026","og_description":"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_author":"http:\/\/www.facebook.com\/phlocblogger","article_published_time":"2015-09-30T19:21:23+00:00","article_modified_time":"2018-01-05T16:01:44+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","type":"image\/jpeg"}],"author":"Piyas De","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/phloxblog","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Piyas De","Est. reading time":"19 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/"},"author":{"name":"Piyas De","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/7aab6e040a06f0dfe0d60c27768aa424"},"headline":"Node.js: Express tutorial","datePublished":"2015-09-30T19:21:23+00:00","dateModified":"2018-01-05T16:01:44+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/"},"wordCount":2405,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","articleSection":["Node.js"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/","name":"Node.js: Express tutorial - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","datePublished":"2015-09-30T19:21:23+00:00","dateModified":"2018-01-05T16:01:44+00:00","description":"This article is part of our Academy Course titled Building web apps with Node.js. In this course, you will get introduced to Node.js. You will learn how","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/nodejs-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/node-js\/node-js-express-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"Node.js","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/node-js\/"},{"@type":"ListItem","position":4,"name":"Node.js: Express tutorial"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/7aab6e040a06f0dfe0d60c27768aa424","name":"Piyas De","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/eadd6728b7b5be23f0d6585da1a953926e49c6f2369703d6cb4f1147d4dd2203?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/eadd6728b7b5be23f0d6585da1a953926e49c6f2369703d6cb4f1147d4dd2203?s=96&d=mm&r=g","caption":"Piyas De"},"description":"Piyas is Sun Microsystems certified Enterprise Architect with 10+ years of professional IT experience in various areas such as Architecture Definition, Define Enterprise Application, Client-server\/e-business solutions.Currently he is engaged in providing solutions for digital asset management in media companies.He is also founder and main author of \"Technical Blogs (Blog about small technical Know hows)\"","sameAs":["http:\/\/www.phloxblog.in","http:\/\/www.facebook.com\/phlocblogger","http:\/\/in.linkedin.com\/in\/piyasde","https:\/\/x.com\/https:\/\/twitter.com\/phloxblog"],"url":"https:\/\/www.webcodegeeks.com\/author\/piyas-de\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/7578","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=7578"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/7578\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/924"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=7578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=7578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=7578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}