{"id":1525,"date":"2022-12-06T11:48:23","date_gmt":"2022-12-06T11:48:23","guid":{"rendered":"https:\/\/www.workfall.com\/learning\/blog\/?p=1525"},"modified":"2025-09-24T07:30:48","modified_gmt":"2025-09-24T07:30:48","slug":"how-to-configure-cors-in-node-js-with-express","status":"publish","type":"post","link":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/","title":{"rendered":"How to Configure CORS in Node.js With Express?"},"content":{"rendered":"<span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">9<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span>\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/JrunqGHz_o6UP2yIAVoDx9ZBeCC7f7_qxFY0NtbR-iJx0q_eiSzIhw80N0tQPk9RpOKanSNVhk9m3GLW5-Y7yye8pzf61Tqo4a9e9CinySnS2n406Kn3AlclKzJr9hQgTek_6r_idpYNvEXgAEjrvqVhVWsqODoUQUNEx3oilIPvWe3fT6iedLihO3Mt05wy\" alt=\"How to Configure CORS in Node.js With Express?\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Internet browsers typically deny access to unknown websites from your application programming interfaces and services. Doing this allows your server to share its resources only with clients that are on the same domain as yours and nobody else. However, there are times when you would like to relax this guard or would want to exercise more control over which websites should be allowed access to your server\u2019s resources. Implementing CORS in Node.js on your server is the answer to such cases.<\/p>\n\n\n\n<p>In this blog, we will cover:<\/p>\n\n\n\n<ul><li>What is CORS in Node.js with Express?<\/li><li>What is Express.js?<\/li><li>What is Nodemon?<\/li><li>Hands-on<\/li><li>Conclusion<\/li><\/ul>\n\n\n\n<h2>What is CORS in Node.js With Express?<\/h2>\n\n\n\n<p class=\"has-text-align-justify\">CORS is an acronym that stands for &#8220;Cross-Origin Resource Sharing.&#8221; Cross-Origin Resource Sharing (CORS) is a browser-implemented HTTP-header-based mechanism that allows a server or an API (Application Programming Interface) to indicate any origins (different in terms of protocol, hostname, or port) other than its own, from which the unknown origin can access and load resources.<\/p>\n\n\n\n<h2>What is Express?<\/h2>\n\n\n\n<p class=\"has-text-align-justify\">Express is a lightweight and adaptable Node.js web application framework that offers a comprehensive set of features for web and mobile applications. Creating a robust API is quick and easy with a plethora of HTTP utility methods and middleware at your disposal. Express adds a thin layer of fundamental web application features without interfering with the Node.js features you already know and love. Express is the foundation of many popular frameworks.<\/p>\n\n\n\n<p>To know more about Express, refer to our blog <a href=\"https:\/\/www.workfall.com\/learning\/blog\/how-to-perform-a-session-based-user-authentication-in-express-js\/\">here<\/a>.<\/p>\n\n\n\n<h2>What is Nodemon?<\/h2>\n\n\n\n<p class=\"has-text-align-justify\">Nodemon is a popular tool for the development of node.js-based applications. It simply restarts the node application whenever it notices changes in the file in your project&#8217;s working directory.<\/p>\n\n\n\n<h3>Required Installations<\/h3>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/dOTKX2F__lDVcSr2rJcDwXi8tcE8STzqdRBAh8ayzbSTmYrnraAy8X6HjlAiEfc8afCqYPB6F5XnTGsbTrRnEFOTb2DqaQju52K3_1VVe_c0SIPi06FnFj84kR0gZzHWksx5uQCtHAuUWnEgap0JHLQ5tV76-PDnTzyMuqUH3KbBS2h7m2AW6_8DmZa7wGQ9\" alt=\"How to Configure CORS in Node.js With Express?\"\/><\/figure>\n\n\n\n<ul><li><strong>CORS: <\/strong>It is a package that helps us enable cross-origin requests with various options.<\/li><li><strong>Express: <\/strong>It is basically a back-end web application framework for Node.js designed for building various web applications and APIs.<\/li><li><strong>Nodemon: <\/strong>It is a tool that automatically restarts the server whenever it detects any changes in the codebase.<\/li><\/ul>\n\n\n\n<h2>Hands-on<\/h2>\n\n\n\n<p class=\"has-text-align-justify\">In this hands-on, we will see how we can enable and use CORS in Node.js with Express. We will begin with creating a new directory on the local machine. Followed by that, we will initialize the application using git bash. Confirming the initialization, we will then install the required packages. Confirming the package installations, we will fill in the code with the route of the &#8216;GET&#8217; method. Spinning up the server, we will hit the localhost URL and check if we get the data.<\/p>\n\n\n\n<p class=\"has-text-align-justify\">Then we will navigate to the different external sites and run the fetch method for the same URL in the sites console. Post seeing the CORS error, we will navigate back to the codebase and add the following sites in the origin so that we can resolve the error and fetch all the data. Then we will see how we can enable cors across all the websites. Post enabling it, we will check the same on the different sites&#8217; consoles to see if we get the data using the fetch method.<\/p>\n\n\n\n<p class=\"has-text-align-justify\">Followed by that, we will have a look at how we can whitelist servers for enabling cors on specific environments. Then we will have a look at the different methods that can be enabled via cors to be able to use those methods across different websites and finally we will look at how CORS can also act as a middleware function in a route.<\/p>\n\n\n\n<p class=\"has-text-align-justify\"><strong><em>Note: <\/em><\/strong><em>Please ensure that Node.js is properly installed onto the local machine or else it might display multiple errors while following the process.<\/em><\/p>\n\n\n\n<p>Create a new directory on your local machine.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/4JEYeEkEGsPblCaAyhd16itj6xqawlzFFUwi_PeuoeipfNpYCtHSh-cZuK5WkqQNXfsTqS5d350rFH5FfX7KLWM6SSp9Z_Z9Az_jjkRZ-Xo00usumInbzDq6_MthvSBzph7RjCSQCMmBQ0etdVgAGo__EcRUmdBgvI1Kfsg3EuHhT8R92UHwTJ5IvKjsG9xW4cb2qaLfqg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Right-click in the directory and select Git Bash here.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/dpo9-uj5Q1WiMjNcxM7l_EtUl8CEOIR9jx2kgNORlKvoIJSwR2DcqgmUwpmdIC9O4FSuR1KUcAkMMPRkOjTb4CSe1RzJ6j6HGRuQuioCGlnOF7ZMFj0Njob6ydnDnYs271ih-hawFaHdOJ8BdCmh0pMrDtF50kr864mDuKVcMhuM-IS8QvPbLJrWDKV9dxAmjxVit_QHyA\" alt=\"\"\/><\/figure>\n\n\n\n<p>In it, initialize the application executing the below command.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/Aow-9TrQuru8_R5uNStqt4rJEv6-c5i8KBIWtTxnbaWQs0bXFDA_LiJOofczdlEVqmsznznA2-AufASyg6GJe9exs5LbXLeLQKSfzQTLsZTlFCPvIqBgEfV71hX0nFHb_IuAHzvGkhZyJK1iwmf3s4ZXrk6VG5rRImCsmMpxDoOAKj6DIuVpt3M9Bh92BIII-NhLhl71OQ\" alt=\"\"\/><\/figure>\n\n\n\n<p>You can select the default configuration for the same.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/36GMlRdlTWANpmRAAYk0tELjey4Ifa7h6PZnHTpIgNloJLafyWefyAcVHmCtZp4KaXa78hhbf_PCbTh9lOkWExZ_YLDpFBkdwj10VL3MS75Yluow7Adwm2JSB5Zej5ypNNm26EuvBH6fGrlkYBP_qPjBYZf2mD4Tzd_GdDH5_EU0YncRgYC_Ho_IzNd8lPeHSWGdqtrSww\" alt=\"\"\/><\/figure>\n\n\n\n<p>Finally, you&#8217;ll get to see the final object of the initialization. Enter yes.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/1m7gf9ID40jndGo6v2v9fMhTSmXyal1Ma_6TbHBLqhYuJBJLy6STMLssAzsA8sOAZdLdRSHsHOC9aBI8WSeE9xL9-Xhr5-q1tETkqdXNzpvi518sdbD76Wt-A8f6-UUgI1KPayj8tslm3ga5jC0wdW9Wg6m96smH-y0k3byElXcgsXo1wL7fSPCy4oRtJu_heTdW3VGTKg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Open the directory into a code editor and you&#8217;ll see a package.json file created.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/IMIvgeVs5D7Fkf9pun5DtoYJMqC-Mru3WeCGDKu3-TbcjHQ5iQCwb2TdgwRsFsK8t9MdtgDUY3TFQ9auI17Sp1LJbq3V-jesihxHYl0TRRZilRyAJKSNNnKmIeoEluKt6AH9Jy4ET-H9GkO5FmoNbDZBNz0osvOgFwl4X-bK61Bi7jIJRkdlwxRVIPN4ss5JiNLTmBafsQ\" alt=\"\"\/><\/figure>\n\n\n\n<p>Open the file and you&#8217;ll see the entire configuration in it.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/VWbY0e9cXeDCw5s8Wxxj14HyEVdKg-moUSsPMdQKeOy_nJHHap5DfF6---tP9eXAa5WxRdFDGpAquiIWZScJZRMPpDGTaqzMZvnwhOxuYgAY8AGlIkKbfmDwNzAkb-zK8M7umxzkiR4Y7N3sMSQXDG_6VBFyeKkmAwmDdsRipFkPPH8huts4NpeCUzqlQ3QtoNAD1XB5BA\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, run the below command to install the cors package.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/uPvoVrjrqItHkQANCTqkOEF_j4NQUXe4vFfKBnt0j5nBUfyAF10X2vcMxJbj1gQ-tCo8KLRkeoFLMctNbQgywLTS-Q_Rq1oe_rYqNtopvf3gGxxanYaA_oy2hU7-fKEYwQIxZwbDWx0k11-9HCxl7igeg0DQo9g9YdueA9lcjTcLR9zpq4xyHyb0g5GNpmSvAisbWTJ8Fw\" alt=\"\"\/><\/figure>\n\n\n\n<p>On success, you will see the below on the screen.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/LoQNPnFJhyFts71xHleI4T-qzcAmgsHEwb2jByjyaG0-kxkd-eVj2O_2loxKgAHV1banFQj5nPN1eg_BZIZdp61cEY0AisXXvqmHXdvcUsj6vHpf-Yb4xq_FsqjZMmNz9htijykFMWfJB_TQiQbZteMV6iy9HjSMN5UmqanMrZIQRvo5CFCe8UhPOlme7IlxBObMNzDMeg\" alt=\"\"\/><\/figure>\n\n\n\n<p>We also need to install the express package to be able to use the cors package.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/Tdz-rPvlD4M4xQBaMvmpYParfUb_4-I69Lur5o7ZJRs2sqZcitW70-1uT02WEWfaRhHYtA8k8MYh_Aq5liNtVby0ZFheH15wVqi3DmQF23z93ezXZdMSFK8Y6L2IifeIF22Sr7NFxAp6j3igOfkKeqnYDtcYvyHu62wAAfIbeLomqQ_QFDjnm34EShUAdQ4ta1ExzbIgXw\" alt=\"\"\/><\/figure>\n\n\n\n<p>On success, you will see the screen as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/5J5vL0QG3NgRuz9S1HKyzeftuzXIpJsgtBfhFkC8KDk4OgZ4HK0MADDtB0bdzHvrEmCvcv9VruISyIK0In8q7GsP8I7ECOIogscgjmh92wCtNQhEzrJmZnSBO82fuDKQ7ayRrXIcu2hXY_N0STkzHK2iMnlZGn14lkFiSJ1EoNK8dqgXaezJ1i6fBUnVc9mir5RkXnWYEw\" alt=\"\"\/><\/figure>\n\n\n\n<p>Finally, we&#8217;ll install the nodemon package so that the server restarts every time we make a change in the codebase.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/1xR0CH9l8lHe97fVN0mABANDJfhzrMfHx1KHo2r7r1CpY4_2l8j3M7QJ9YslyAtZNk9o_2WGA7ZWpyTqgDjrBQMjwLbdQz0KgwO9yL4Vt8S_nWY3nOaknAI_wmgvbE4GRIN33cuh1ApL9dFHGm7jg_lKN3bbMEpfNfzeYjvEm4t-9WDVyS1uaRWopqMtUPm3WxMwkkr7Zw\" alt=\"\"\/><\/figure>\n\n\n\n<p>On success, you will see the success screen as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/T889d5z3yse91QPq_3LoHttZof3x9UDl5UffvilYwuH40Lz_djAj-JD_pMyWSS3FAqdzcKVy6_vZBCuxkZANHXtia08Dp-r_lc8NXsGZPqQLw4lzarXRBnWPu15Aa4NKI7ono61BNhDCYpwyJPj-I1dV8PSBxUncwA4cV7UEBr7ayJMbBIheBMbAsIvoSSffjQtVkEWXHg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, open the package.json file and verify the installation of all the packages.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/XfB4UK9ldZ15K_GEWnRDqAViymGocWpX2IsIUBW66Ms-4iRqIggibCpPZ0lzo44PCB8CToVSqj4SON8e3m3IyEo5x-3B6ZVsy9IvRlsK2e87p8ckWBEL3nx6t5CgBYqRoPL9CIfzh1wHSJtfns_3utISTHSffIRFbk7e0MJuAtDtclPYkFZNksL8Ctzrn3HupxTsDAPkiw\" alt=\"\"\/><\/figure>\n\n\n\n<p>You&#8217;ll also see the following files added to your code directory.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/e7MZcWa4Roenp1-LNl4qwqVzY2CRmhYqgGBjuGRfbolnlzwISglwXZDW7Rx8tcngSUbOX6U21zfsUU76l1oQT4EmBCciH_n3lh4MR5ZVLZGt2s2O229zBTY_Ri8b64-BbNYFkWYYr8jMICB1_2Iw83j55sQuRqvrQKOWzx9emEMu2ZeqTW6m7yQZ6DNQsIR5jR2vlMVeQA\" alt=\"\"\/><\/figure>\n\n\n\n<p>Create a new file in the directory with the name index.js.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/ccCw8a1plruBJUsO-DOxMCAQOLR2u97vurXR2coGbWD4eDigNhH-WFE2UF6eLrvlyQVNAF1IkBK7pZWJA4jvKqLPTi_wf-XNb1IemqA9pW-yEwzrQc-zCNgIeePAKHFBE5yD80sZtq_FsZplAFfA0xwDRYHTN5MOcP2vnRnnAvBWK3VEfTQ-5xK7IYgS5XZWId8wnO3IRw\" alt=\"\"\/><\/figure>\n\n\n\n<p>Open the index.js file and import the express package in it.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/eo6zSJBLT9xPI915CATPQ3gqbW53JdcSg_Uf9cl67eaMJcu89T7BvYuwacjwwEiYp9dnf9M2FEisE3uESPmBhR4PwtgpOnIgl2x2bwSLjIOJHQIi2qzCfQyIG0cD-y5kU6FTlIJql_JkP5EJYWlBIKMbdI9uTw2OuBZabigYPJcVfvFQblb4j-72OpsoZyutGaELSlyK9Q\" alt=\"\"\/><\/figure>\n\n\n\n<p>Create an array of objects with some users in it.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/VAazeOwwt2SxooVvvPg9Lrgo6Db9QrX3tz9Gyz54CrQiljUp9v4ur8HNaTjBbd_IUvLVXH_PM1TaGbwcUXXPXJNr4ht5zhcXuwAUv9eJ6rUunulBqBVGtCZMxqmN8Ud-lZK-D88kgZ586bvhNvO_xBtASpYuPQHLW56erlBykrsiKzrt-z8WgXhSbp9clUJ3q__-_a-mJA\" alt=\"\"\/><\/figure>\n\n\n\n<p>Create a get request route with the route URL to get the users on hitting the URL.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/Inf5cTqQNy4u2HNG-41VkhZ2Hb8jVhnybxYcbB8PMwBmr2JYZPZik5ULQVXyasWuh_amp8jFWQfrE4q78uOuPrLlABw7qAKkccq9R-fbR4rhdAxVm_7VUbLK9RJ7epjm3Ta_T_1QSoBDc8lXUnJsebueaKtTV6WWVTWDVNPHLvKMCd3x2_3XELnv5Pl8Fbcf5AmjSjKYfw\" alt=\"\"\/><\/figure>\n\n\n\n<p>Finally, initialize the server to run on port 3000.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/r4mf4yztC1YfdxQOeJngl3T7u1B34A5pbwqyt-qE4gp85n2v6NNWNYezuPrc8OB0lq8ATN0IGviUPOV91Cp-8fRAop707IxwuPFg1geqyhmX7YAckTDMOv5w5qTPybOI3C__SpHh-7Z539Te57Bzb0z3L9v6VHSDEncxqkzx2Ttxg6KnNwjrUoQWwiMhoGR3Iig776f9Qw\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Now, in order to use the nodemon package, go to the package.json file and alter the script parameter as shown in the image below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/bt6yJu4sDir5MqDItjnniR3OZLQa9Y_7woHqvxkmhQpU75l2nXdo6BZ0YKs2u_XKPpFWiYKLhtJIdX5o1a7X0jRWifzhd_B5zdu7aha-vZF6xWujt793Ee13iCbwT1qDzCGmiXMXEiRLoMu8tUW8zUlaXC3vpBy0pbvmeZX4Vj73NF78bp6Abg1ujcJk_AiuyIlao-F-TA\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now run the below command to start the server.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/wsMoP5lgjJEUK5vdVdqhMM28ox-6uBW6lO4MDDIQ_HZ4bcGj_102YOgtDyi_36Edl7kn_nse3IstxysBll2bjM28iUyhxEVWwnskiAafURh5e64nSdx_Mzr2r0Cfh2Yk8QtSczMuSghjmOMmRBzH0Oy_lsJUJ9JGMkcvdiGXnkMKrt7NFMIvPy2JthjnG3xtF7Y7qcSDLQ\" alt=\"\"\/><\/figure>\n\n\n\n<p>On success, the server will be started and ready to be served on port 3000.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/gYP6-skJ_3bBFO8HOV25V5wmqVUBV6bNtbFlLJqTA1G1aFISbqPZ7GDljxXJDJ0yvy7i5ctPKmOdFvaEO_j_ZARY9yTPGkOvCT6OrNx9o6gDbpjt47Oy4yPnHlIAD8c3WCQvFaytSYm62vBXQRNhy6a0QT3YISjeA4csNKHDZJQHthqVpoK6sr_2g-RXI4GKKiAB_vtM3g\" alt=\"\"\/><\/figure>\n\n\n\n<p>Hit the following URL.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/KdtnFtNpM2Dk_FbC83IeRwKMrqKkDNUHan9SLsJdobSzbuIcKy3rKUuozoXXA2px0NkfWpRtgMiFJX7-2PYvUTEJ7GnilFHZ5axXEJqp_SAHGtpePgW4oVcxp32a_GY7Wxxltjw-TkcG0pkRho_IAUDfcMVn_C1denfVQvGEhGpkS5X8hNegVY7oEwcgI5auoHUKL5GQmw\" alt=\"\"\/><\/figure>\n\n\n\n<p>You&#8217;ll get to see all the fetched users.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/Ggf4Z3AhrgX82c7QLLa72gp38Al41sepzCYbmat3t7145OSTIV3GOzB84zgQ9VaIFW1CuvJ66kzFGr62ypVgMy8czS4OP7koJamqeO8ckwluQqaZnTt6wqGYYSPEtdP_QVshTLIKURloskQDGqipadpsmIKQtAkZL9tdb52oByl_8-zADx4BKFTaO7GDufHjp9SVesdJAg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, navigate to the workfall website.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/zD-Xbha9r2lSDb5X_xDDLIKKdeSOdmoh_Z0IKyOKxiN9p__e8GbfGWvV9uTLmBBucteho-4y3r-uPqEw8EGKX1dPs4Idry25-RwIdMR4sV2PCD42aK1cWOZu08sc-S7QBgQBiHV42UZUBcYWG4pfkGtjueeDpQUqzpL2-zgLc7fu-k6Fk9yzw5YbRHUsSsyrYx0lja38Bg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Right-click on the website and click on Inspect or press F12.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/4zf8UaicQFEbdI63B5eR44_Ug1E3DkwzzD_78Y2jfdvDLU7ZYM2fBtFKydmdHrKMurtlKAAhdT0Awdri27kmgiE6-fLQLq0j2Cp4B2vCcUPBYYlOR-5YewgJoWh3k40PAaXEymc6KG_3GeQEuKC8yPfaakvruM8wosvci2hONy6eNQL8z7Fwve06kyyvcB9mpv1tQkB2rw\" alt=\"\"\/><\/figure>\n\n\n\n<p>Navigate to the console tab and clear the screen.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/AF8QztmgCblCnadCJhMhC1EOWddIaxiXaExSIY-7qVJttmArR_mMN3HxnX9ZXjpqPAkQPwivYeVZMIAniQTNF4R5dpfcAgNJse_xTpWArdulbTkmBCXYZc543rZtXE5bcBExrsdEeKJ-KNwjMOEn7bC92l3p4wnZTGI8ckW_zFfQ1pTA-ygN8FA55jTsvt-RoA_gdwUrkA\" alt=\"\"\/><\/figure>\n\n\n\n<p>Use the fetch method with the following URL to get the users.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/SWZth0eYEgo8cAEQ0_jMhQCLDiUcI8YtwopbmOrlOr_FmiJjT56JXXkkUpEntt7CYTwJuq0ZAdzUL59pKtC75MweTvsbNzL8FNY3oIMTtO_c4UMrGuR_SeowIoT8Z298GqZ7I3BYfsSuodPqozGBrrka0UITVINqkeOoYBY7VmUZHFNUM3voMvBJ-sx0buAeMeGdn1DGTQ\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Since cors is not enabled, if you try to get the user details on any other site, you will get the following error message.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/sVxifghW4dZGRNjvk46W-YtgQ2u2APUGI9yq2-wp94_k8dtFALsv4qlNqHjNJojveTOaslNnKx1rHo2xYbKL4sreEvsm0IYc94Ozqga_NTF7NZQiPyPkg6DlwzIm_e88OrZ83P04SRnvB6f6e9K3AiFEosYfpXh68ZrhzdGx-5cAZdTvucyfPdWYOIjZ9b8GeK0o6AuUeg\" alt=\"\"\/><\/figure>\n\n\n\n<p>To resolve the above error, import the cors package in the index.js file.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/qKZy_dX5qZqJYywreDgt91SrcpdeN8f6EpbcY2qshmMTPspljO4tjk8XDAq1pEe8dEWwhh9Z89geLTFnFivHwkfp7We-LS63SY_jrIZEOCHKMfHLJHdCqSwxmfJuAK3bE3q_fDAC2XsT93aSKnApFbMQBLPBn4HurqhcZXSzpx-2ir53MoswoGeyhjzqQxXTCetOBRVkXg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Use the following code adding the origin as the website we tried to use the fetch method on.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/5jk5Vo2E6wf-rH1Zre11nUklCZGblrsnAZM6w6JFrahXmX-Qe2CCMPH14lGBdiFevIsp1SwHmByDfIp48xElFvxqBZ8idtEMBUQeN194nWvxJgCO079A7KQbH1ifhlMGYmr0zSTUeRPM4ngCcgRlRkVAq7l-gJDZdhf-WGcWNZBEWTBT-qgqoryQymznCAUORLnqUdXVQg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Ensure that the server is up and running.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/jytPaNwdrVcX0ZfT-PG4oPzj33F6oWdjLRammUHEJFeUzGKM3ploI5vIYxGYliWqUCpNBZZ9_FhFyfhZ9vLEqBGam3qZS_ZaTF-PFDfJbBDDbk20fCa1Wx27ncUl4VZbYqmEGkhjawnQcZ6thPTvhAIUPJwCsfFgi93Oj7OkeVrjTh36WCISQ6ysXunw9QwOpLeNEZ5AdQ\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Navigate back to the website&#8217;s console and run the same method again. You&#8217;ll see that you won&#8217;t get the error message anymore and you&#8217;ll see the user details fetched and displayed on the console.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/OzJtK7TTlGA2A1S32W2OSIrbnUBQbEaolAszsXcCXoKHx__doG8EN__6RisKkDk8HZBRw0AOgvjI62vtLBPldKFE-PuFtBM7V5FdXWwxvQd79Ta071WdsTsABe3MtJrmNqRqOQMp07rQg1hG9Z4hAaLIzyYctDwt9FuJ1ZbWDmgTH6ofQUtdNKyVr5v53VaxwISUATZXLg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, let&#8217;s try the same from a different URL. Navigate to Google&#8217;s page.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/dQrJDQ3jZuVemyRbHPkUX1lhlfGVjpIVZjHPVPG_jFYaGzLfN0iXBXcDo4SWgV4BKSMiqYJ9vG5NHN0aHCXleAe_1hUYVpGjXvREVmgwNjwcQ36Z5cdj5NW3vx0ZZha3YH3MC2vupW3AVCYkgv4noQPfscoaIlI3mC0_BDTxGB5IcdFU8kbrmbRuD7iSytHooAZU_pODUQ\" alt=\"\"\/><\/figure>\n\n\n\n<p>Go to its console and enter the following method in the console.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/Lk_NwkGP-BiMzxvR8cYA8T0Ti_n9iCGoeD5fbmo0x0FbilBxtfG7Lgtsenf53LMjV0Dkr3CGNkVFclEapdGijODJFsDHSmTqKRp6zUpyj9YVt5QsQc7QS56FqN563-rIXfZweqZ0OfSB-bY2pCowsarsiLtmlkSnHHdh5NdX1XkDp_pOWbt4TDCjx0Px8PMJrEMz8RY6bg\" alt=\"\"\/><\/figure>\n\n\n\n<p>You will get to see the same error message again.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/V7rUPUImjqw5Wyg85JWMzZsXs5EmGk-cc4Hw7EOaT78P_qtLKnuVA2P4HlAv5M4XNxdKPySxLoFvtDI08cLwFC9KrOYZT989aEpOWTo3F0QaHxOTpFvY1VHoGZKxd35LwN7YYV6qKCHf6moHA-SnnhbS7xsZ5awgUHQQbOBthzEnt22rZzydLWfucRfcz4YbTKgnfQoR4w\" alt=\"\"\/><\/figure>\n\n\n\n<p>To resolve the error message, navigate back to the codebase and add the google server in the list format in origin.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/ryEnJno4sP3fHN961kCXMgQep7Zko5CMYQGPJXwYjaUjfuaHWpAqG9MSRj_AELwc-y-bXRB8e8Mk6G9xufh8k8cSLj-4WpREGJ-nntcn0PwPiDp1p_0-gm-HKM0uTjYPAoc5PzYvhH4UArVVYc5vEdjCuPuldYGa1kwbUZsIPBXlgLau4t7Xw1TF0hteaaJAh26p_NAnKQ\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now, navigate back to the console and hit the URL again. You will see that the result will now be displayed thereby fetching all the data.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/8yQ1Lc30FTJwz1X46LpPtD544A5tQohWdTbK1W-kHsfjOlmvQxHtySd0BXxlstfgdemugG_3G7k4hlPmggYjAw393c8PTl4fTqZqBCuEeGQ7OKfpKA5nPJESn96cCHMo4AFf2D0ReCIZY2etO7pWSaj2rJ9cVY79vMDzCu63dErpZGwfDIvM0hvX83_xKkAf3LU3of7stA\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Now, if you need to enable cors on all the sites and make the data available across then you can change the origin to a star which means that you can use cors enabled for all websites.&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/qdGZQ5_k_SLDgYoencpXYCJa_XH-HlAGR3laDdqqajPKEHVPDpUY9NVtXJsBeXqPaTDSowPNfHvW56oe8pIAbnoqUBUKiB4xGqxsPhMe19m1MrT2-nvw_DgAkzmf6iI4beZui1bMZvGitBSQFB8UEnH4plVRPZTKcErF3wjBXG67iDeyy_1JVpbchxnr_rvNBea2i7Dajg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Navigate to the google page.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh5.googleusercontent.com\/gdL9PBbTIvRrDhYYvWPXussRmE7Rd2VwfH5nTRq72t04FyAAHIuok9aHG1sNY4HU6Nrk8unWqVRtkkT4IP7PrzS7WxlSB2oPXoEF6nE_FAzQPhEqi5G35O62tqMdMAd6gDwjHHM_aEJskfLkrPyOh6lT0pzBvDC1FjZZNPfQ0Xk_6WwMhzHy5HyjNuAaqsNmUpXpw2e0tg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Go to its console and hit the URL using the fetch method. You will get the response as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/cxOy8IPZ9BP4vMF_WXvQgu-Nh1UBYDz8_p3aeZcaUBr7y6C8fuR5dPhDEbT-H7GJC_oq9ZzXHkRCCjgXA3dkiQyrPiBy43ql6GwCbCZCpdQXllGsRkTdfIZrAA7YJTkEJinywS6kSBwxDQyTk1hzHMdaUmjdaHwPTWVncn3pulmj8YC0pIgcL1d20rub9GEJtb-oTxhVOA\" alt=\"\"\/><\/figure>\n\n\n\n<p>Navigate to the workfall site.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/wqUi3Fak3G55PUj8RFYsGZDaSTUO8Te56x5hxuT_PGwMFJ89k3bUS8pg08ZGIOc8r1Tvtk9Rni9vVy1xU84svWXU8pXov0vTvaATeG5R7-Tcv4fV9ZK-aRznJEF8HsyljVHmGSNAdYB3lDFCjBkzLttnCp4RGGIjWczyrsIACyjKH_Fw2RsAnnScpT6RzQZWbRGcmV_BWA\" alt=\"\"\/><\/figure>\n\n\n\n<p>Run the same method in the console and you&#8217;ll get to see the data.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/P0K9oFkoJvo-BNY3gEJW7IomKgXyd-_1sdrJHA84ahOcooX_aVC0Nl2EXSrw_d65D4Vvz8BCr0mmgKZ5aQeSBJA_4Sj-jkxtSarF25t9DFnmK_FNqb_5G_4Lh_JD54QcUSzGxmN5LJtpfg1e_lcousj4Pug8N1MGJuoJKV4SLGbqSJgn7kMJMz74DEnCf62VuviajOtktg\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now as for the third test case. Navigate to Wikipedia&#8217;s official site.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/kP9RGU1LeXisXKw6p87RWwr95gxwuio0EaXxI2yEc3Ne4ttl0RXJ20UmLDn5CfPx4f4_gO8DG4ckgqg-oEmhrJeiPWMpktOeuOhx7VYdwb6QUcEOb4-69VkY9t_ymq4mF3jABjiSU22bpyyDG4Sl-aWK_QQZjoC4mUZXLWaesXOGopfrj0k0beAgBy850qoKCawTtgx4dg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Run the fetch method in its console and you&#8217;ll see the expected output with the list of all the users displayed on the UI.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/owq_tB6flP9rmMhOscprf9-Bo-b2J7opjHgiDdIJ-KYGXgTa59NB8cWlyzEvozNpDtR1_kmfMlrR7jayVwcN3EonEq3TZHJ47pxBNzZNVXwRCwrgmkjwYaYV63ADYVsS9ACIopm1j1IDJ-W0EMEyEo_-tiaqsPqhygaC442oPAnEk4TEGBBc9ubNsj7NQUppjIFifSgVLQ\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">In case you have different environments for your application and you wish to enable cors only for the specific environments then you can whitelist the same using the below code and return an error using the callback function as shown below for other than the whitelisted servers.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh4.googleusercontent.com\/Nrx-1OmHI678jAxBijO3EDkXn5EKv_l1z7VL3-VzPlWzeXmv8-5YQLayoBh0bsvo0LRrmZbJRi_yVSotwjxIzAghwPbG6s8l8ojVcXxVAnt8bdwraJ9YbHLDblrqjPR4PeFRHkeUWM_2NmNGYmvgObmRvVVzRkC6_qhQfNHAzgnjXgDHFkcSirIymnztWQYflVZhOr_Zgg\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">Cors can be enabled for multiple methods and not just the GET method. You can also enable it for methods like PUT, UPDATE, DELETE.etc. using the below code.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh6.googleusercontent.com\/278IrW7d07Up45YuoPGx3A1t9JgfyjQgjZWox0XRoLX1TGTZJ15jGJW4VJ6VWfyc9t9VtLKiy3hiKcod8bDhp5NPEtOSXKJBjgZVwIqwUPRrx4OU4JY6ZROcGa9R2_4ZIBJiiLFK0eBi8eCQ464isxo7EDox9RY7lEYu5S0qwPVVr21RCjMtFFdxY5zbuO-ujJEQbHh68A\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-align-justify\">We can also pass cors as a parameter to the route as a middleware function which in turn will make the checks to enable cors or not for a specific method.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img src=\"https:\/\/lh3.googleusercontent.com\/7FZ2-Zb6mBlRuejIhDUAwmtrJs_zWoxQml6WvftR3oi97xGp5wy_r2xYVFkLWwUgyrGoWRSanJ2dvVE26RimOLkMCYIA64UvrVGChEAq6AQWVvPuGPiF2C01yy5kj5pgeLW4v0ogBsbJh5grXFbADaSWbJWbqsxzFYz4o3mmQNEj1bf1BtflEL97kjyYjdEH2bpW-NNLQw\" alt=\"\"\/><\/figure>\n\n\n\n<h2>Conclusion<\/h2>\n\n\n\n<p class=\"has-text-align-justify\">In this hands-on, we saw how we can enable and use CORS in Node.js with Express. We began with creating a new directory on the local machine.<\/p>\n\n\n\n<p class=\"has-text-align-justify\">Followed by that, we initialized the application using git bash. Confirming the initialization, we then installed the required packages. Confirming the package installations, we filled in the code with the route of the &#8216;GET&#8217; method. Spinning up the server, we hit the localhost URL and checked if we got the data.<\/p>\n\n\n\n<p class=\"has-text-align-justify\">Then we navigated to the different external sites and ran the fetch method for the same URL in the sites console. After seeing the CORS error, we navigated back to the codebase and added the following sites in the origin so that we could resolve the error and fetch all the data.<\/p>\n\n\n\n<p class=\"has-text-align-justify\">Then we saw how we can enable cors across all the websites. Post enabling it, we checked the same on the different sites&#8217; consoles to see if we got the data using the fetch method. Followed by that, we had a look at how we could whitelist servers for enabling cors on specific environments.<\/p>\n\n\n\n<p class=\"has-text-align-justify\">Then we had a look at the different methods that can be enabled via cors to be able to use those methods across different websites and finally, we looked at how cors can also act as a middleware function in a route. We will come up with more such use cases in our upcoming blogs.<\/p>\n\n\n\n<p><strong>Meanwhile\u2026<\/strong><\/p>\n\n\n\n<p class=\"has-text-align-justify\">If you are an aspiring Node.js Lover and want to explore more about the above topics, here are a few of our blogs for your reference:<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/www.workfall.com\/learning\/blog\/how-to-perform-a-session-based-user-authentication-in-express-js\/\">How to Perform a Session-based User Authentication in Express.js?<\/a><\/li><li><a href=\"https:\/\/www.workfall.com\/learning\/blog\/how-to-perform-encryption-and-decryption-of-messages-using-crypto-in-node-js\/\">How to perform encryption and decryption of messages using Crypto in Node.js?<\/a><\/li><li><a href=\"https:\/\/www.workfall.com\/learning\/blog\/how-to-connect-to-mongodb-using-mongoose-and-mongodb-atlas-in-node-js\/\">How to connect to MongoDB using Mongoose and MongoDB Atlas in Node.js?<\/a><\/li><\/ul>\n\n\n\n<p>Stay tuned to get all the updates about our upcoming blogs on the cloud and the latest technologies.<\/p>\n\n\n\n<p><strong>Keep Exploring -&gt; Keep Learning -&gt; Keep Mastering&nbsp;<\/strong><\/p>\n\n\n\n<p class=\"has-text-align-justify\">At <a href=\"https:\/\/www.workfall.com\/\">Workfall<\/a>, we strive to provide the best tech and pay opportunities to kickass coders around the world. If you\u2019re looking to work with global clients, build cutting-edge products and make big bucks doing so, give it a shot at <a href=\"https:\/\/www.workfall.com\/partner\/\">workfall.com\/partner<\/a> today!<\/p>\n\n\n\n<p><\/p>\n\n\n<style type=\"text\/css\"><\/style><section id='' \n                class='helpie-faq accordions faq-toggle open-first groupSettings-514__enabled' \n                data-collection='' \n                data-pagination='0' \n                data-search='0' \n                data-pagination-enabled='0'\n                role='region'\n                aria-label='FAQ Section'\n                aria-live='polite'><h3 class=\"collection-title\">Frequently Asked Questions:<\/h3><article class=\"accordion \"><div class='helpie-faq-row'><div class='helpie-faq-col helpie-faq-col-12' ><ul><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-2915\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-2915\"\r\n                data-id=\"post-2915\" \r\n                data-item=\"hfaq-post-2915\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. What is CORS?<\/div><\/div><div id=\"accordion-content-post-2915\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-2915\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">9<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><span style=\"font-weight: 400\"><strong>\u00a0A:<\/strong> CORS stands for Cross-Origin Resource Sharing. It&#8217;s a mechanism that allows a server to specify which origins (domains, protocols, or ports) are allowed to access its resources. Browsers enforce cross-origin rules to protect users; CORS gives controlled access.<\/span><\/p>\n<\/div><\/li><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-2916\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-2916\"\r\n                data-id=\"post-2916\" \r\n                data-item=\"hfaq-post-2916\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. Why do we need to configure CORS in Express?<\/div><\/div><div id=\"accordion-content-post-2916\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-2916\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">9<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><span style=\"font-weight: 400\"><strong>\u00a0A:<\/strong> If you are building an API or server and your front-end (or another client) is hosted on a different origin (domain\/port\/protocol), the browser will block requests by default due to same-origin policy. Enabling\/configuring CORS allows these cross-origin requests to succeed under the right circumstances.<\/span><\/p>\n<\/div><\/li><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-2917\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-2917\"\r\n                data-id=\"post-2917\" \r\n                data-item=\"hfaq-post-2917\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. What tools\/packages are used?<\/div><\/div><div id=\"accordion-content-post-2917\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-2917\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">9<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><span style=\"font-weight: 400\"><strong>A:<\/strong> The <\/span><span style=\"font-weight: 400\">cors<\/span><span style=\"font-weight: 400\"> npm package; Express; <\/span><span style=\"font-weight: 400\">nodemon<\/span><span style=\"font-weight: 400\"> (for development auto-reload).<\/span><\/p>\n<\/div><\/li><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-2918\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-2918\"\r\n                data-id=\"post-2918\" \r\n                data-item=\"hfaq-post-2918\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. What are the typical ways to enable CORS?<\/div><\/div><div id=\"accordion-content-post-2918\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-2918\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">9<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><span style=\"font-weight: 400\">A:<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400\">Globally: enabling CORS for all routes and origins (e.g. <\/span><span style=\"font-weight: 400\">app.use(cors())<\/span><span style=\"font-weight: 400\">)<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<li><span style=\"font-weight: 400\">Whitelisting specific origins: passing an array of allowed origins and rejecting others via a callback or middleware.<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<li><span style=\"font-weight: 400\">Restricting HTTP methods (GET, POST, etc.).<\/span><span style=\"font-weight: 400\">\n<p><\/span><\/li>\n<li><span style=\"font-weight: 400\">Using CORS as route-specific middleware.<\/span><span style=\"font-weight: 400\"><br \/>\n<\/span><\/li>\n<\/ul>\n<\/div><\/li><li class=\"accordion__item \"><div class=\"accordion__header \" \r\n                id=\"accordion-header-post-2919\"\r\n                role=\"button\"\r\n                aria-expanded=\"false\"\r\n                aria-controls=\"accordion-content-post-2919\"\r\n                data-id=\"post-2919\" \r\n                data-item=\"hfaq-post-2919\" \r\n                style=\"background:transparent;\" \r\n                data-tags=\"\"\r\n                tabindex=\"0\"><div class=\"accordion__title\">Q. How to test or reproduce CORS errors?<\/div><\/div><div id=\"accordion-content-post-2919\" \r\n                class=\"accordion__body\" \r\n                role=\"region\"\r\n                aria-labelledby=\"accordion-header-post-2919\"\r\n                style=\"background:transparent;\"><p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">9<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span><span style=\"font-weight: 400\"><strong>\u00a0A:<\/strong> One can try to fetch from an origin different from the API server in the browser console (or from a different domain). If CORS is not enabled properly, the browser logs a CORS error and blocks the request. Then enable CORS (or adjust origin whitelist) and test again to see that request succeeds.<\/span><\/p>\n<\/div><\/li><\/ul><\/div><\/div><\/article><\/section>\n","protected":false},"excerpt":{"rendered":"<p><span class=\"rt-reading-time\" style=\"display: block;\"><span class=\"rt-label rt-prefix\">Reading Time: <\/span> <span class=\"rt-time\">9<\/span> <span class=\"rt-label rt-postfix\">minutes<\/span><\/span> Internet browsers typically deny access to unknown websites from your application programming interfaces and services. Doing this allows your server to share its resources only with clients that are on the same domain as yours and nobody else. However, there are times when you would like to relax this guard or would want to exercise [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1526,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"spay_email":""},"categories":[288],"tags":[85,367,251,301,265,250,368,6],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Configure CORS in Node.js With Express? - The Workfall Blog<\/title>\n<meta name=\"description\" content=\"Internet browsers typically deny access to unknown websites from your application programming interfaces and services.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Configure CORS in Node.js With Express? - The Workfall Blog\" \/>\n<meta property=\"og:description\" content=\"Internet browsers typically deny access to unknown websites from your application programming interfaces and services.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/\" \/>\n<meta property=\"og:site_name\" content=\"The Workfall Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/facebook.com\/workfall\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-06T11:48:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-24T07:30:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/12\/Cover-Images_Part2-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@workfall\" \/>\n<meta name=\"twitter:site\" content=\"@workfall\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Workfall\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"18 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#organization\",\"name\":\"Workfall - Hire #Kickass Coders On Demand\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/\",\"sameAs\":[\"https:\/\/www.instagram.com\/workfall\/\",\"https:\/\/www.linkedin.com\/company\/workfall\/\",\"https:\/\/facebook.com\/workfall\",\"https:\/\/twitter.com\/workfall\"],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/i1.wp.com\/18.141.20.153\/learning\/blog\/wp-content\/uploads\/2021\/10\/cropped-WF_logo.png?fit=400%2C400\",\"contentUrl\":\"https:\/\/i1.wp.com\/18.141.20.153\/learning\/blog\/wp-content\/uploads\/2021\/10\/cropped-WF_logo.png?fit=400%2C400\",\"width\":400,\"height\":400,\"caption\":\"Workfall - Hire #Kickass Coders On Demand\"},\"image\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#website\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/\",\"name\":\"The Workfall Blog\",\"description\":\"#Tech #Remote #Jobs\",\"publisher\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/learning.workfall.com\/learning\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#primaryimage\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/12\/Cover-Images_Part2-1.png\",\"contentUrl\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/12\/Cover-Images_Part2-1.png\",\"width\":1200,\"height\":628,\"caption\":\"How to Configure CORS in Node.js With Express?\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#webpage\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/\",\"name\":\"How to Configure CORS in Node.js With Express? - The Workfall Blog\",\"isPartOf\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#primaryimage\"},\"datePublished\":\"2022-12-06T11:48:23+00:00\",\"dateModified\":\"2025-09-24T07:30:48+00:00\",\"description\":\"Internet browsers typically deny access to unknown websites from your application programming interfaces and services.\",\"breadcrumb\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/learning.workfall.com\/learning\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Configure CORS in Node.js With Express?\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#webpage\"},\"author\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/cab8236044692bc5b27606b13167794a\"},\"headline\":\"How to Configure CORS in Node.js With Express?\",\"datePublished\":\"2022-12-06T11:48:23+00:00\",\"dateModified\":\"2025-09-24T07:30:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#webpage\"},\"wordCount\":1738,\"publisher\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/12\/Cover-Images_Part2-1.png\",\"keywords\":[\"api\",\"CORS\",\"express\",\"expressjs\",\"node\",\"nodeJS\",\"nodemon\",\"workfall\"],\"articleSection\":[\"Backend Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/cab8236044692bc5b27606b13167794a\",\"name\":\"Workfall\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2023\/09\/avatar_user_1_1693914404-96x96.png\",\"contentUrl\":\"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2023\/09\/avatar_user_1_1693914404-96x96.png\",\"caption\":\"Workfall\"},\"sameAs\":[\"https:\/\/www.workfall.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Configure CORS in Node.js With Express? - The Workfall Blog","description":"Internet browsers typically deny access to unknown websites from your application programming interfaces and services.","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:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/","og_locale":"en_US","og_type":"article","og_title":"How to Configure CORS in Node.js With Express? - The Workfall Blog","og_description":"Internet browsers typically deny access to unknown websites from your application programming interfaces and services.","og_url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/","og_site_name":"The Workfall Blog","article_publisher":"https:\/\/facebook.com\/workfall","article_published_time":"2022-12-06T11:48:23+00:00","article_modified_time":"2025-09-24T07:30:48+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/12\/Cover-Images_Part2-1.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_creator":"@workfall","twitter_site":"@workfall","twitter_misc":{"Written by":"Workfall","Est. reading time":"18 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#organization","name":"Workfall - Hire #Kickass Coders On Demand","url":"https:\/\/learning.workfall.com\/learning\/blog\/","sameAs":["https:\/\/www.instagram.com\/workfall\/","https:\/\/www.linkedin.com\/company\/workfall\/","https:\/\/facebook.com\/workfall","https:\/\/twitter.com\/workfall"],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/i1.wp.com\/18.141.20.153\/learning\/blog\/wp-content\/uploads\/2021\/10\/cropped-WF_logo.png?fit=400%2C400","contentUrl":"https:\/\/i1.wp.com\/18.141.20.153\/learning\/blog\/wp-content\/uploads\/2021\/10\/cropped-WF_logo.png?fit=400%2C400","width":400,"height":400,"caption":"Workfall - Hire #Kickass Coders On Demand"},"image":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#website","url":"https:\/\/learning.workfall.com\/learning\/blog\/","name":"The Workfall Blog","description":"#Tech #Remote #Jobs","publisher":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/learning.workfall.com\/learning\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#primaryimage","url":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/12\/Cover-Images_Part2-1.png","contentUrl":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/12\/Cover-Images_Part2-1.png","width":1200,"height":628,"caption":"How to Configure CORS in Node.js With Express?"},{"@type":"WebPage","@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#webpage","url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/","name":"How to Configure CORS in Node.js With Express? - The Workfall Blog","isPartOf":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#primaryimage"},"datePublished":"2022-12-06T11:48:23+00:00","dateModified":"2025-09-24T07:30:48+00:00","description":"Internet browsers typically deny access to unknown websites from your application programming interfaces and services.","breadcrumb":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/learning.workfall.com\/learning\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Configure CORS in Node.js With Express?"}]},{"@type":"Article","@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#article","isPartOf":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#webpage"},"author":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/cab8236044692bc5b27606b13167794a"},"headline":"How to Configure CORS in Node.js With Express?","datePublished":"2022-12-06T11:48:23+00:00","dateModified":"2025-09-24T07:30:48+00:00","mainEntityOfPage":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#webpage"},"wordCount":1738,"publisher":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/#organization"},"image":{"@id":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-configure-cors-in-node-js-with-express\/#primaryimage"},"thumbnailUrl":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/12\/Cover-Images_Part2-1.png","keywords":["api","CORS","express","expressjs","node","nodeJS","nodemon","workfall"],"articleSection":["Backend Development"],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/cab8236044692bc5b27606b13167794a","name":"Workfall","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/learning.workfall.com\/learning\/blog\/#\/schema\/person\/image\/","url":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2023\/09\/avatar_user_1_1693914404-96x96.png","contentUrl":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2023\/09\/avatar_user_1_1693914404-96x96.png","caption":"Workfall"},"sameAs":["https:\/\/www.workfall.com"]}]}},"jetpack_featured_media_url":"https:\/\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/12\/Cover-Images_Part2-1.png","jetpack-related-posts":[{"id":226,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-build-and-deploy-a-mern-stack-application-on-aws\/","url_meta":{"origin":1525,"position":0},"title":"How to build and deploy a MERN Stack Application on AWS?","date":"October 27, 2021","format":false,"excerpt":"Do you have a wonderful product idea that keeps springing into your head? However, not sure which technology or framework to adopt for easier and faster deployment of scalable web applications, you can go for MERN Stack.\u00a0 A MERN Stack is a collection of front-end, back-end, and database components that\u2026","rel":"","context":"In &quot;AWS Cloud Computing&quot;","img":{"alt_text":"Build and Deploy a MERN Stack Application on AWS","src":"https:\/\/i2.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2021\/10\/MERN.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1121,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-show-flash-messages-in-node-js-using-the-connect-flash-package\/","url_meta":{"origin":1525,"position":1},"title":"How to Show Flash Messages in Node.js using the Connect-flash Package?","date":"August 9, 2022","format":false,"excerpt":"The Node.js Connect-flash module is extremely useful for developers whenever a flash message needs to be sent. When a user is redirected to a specific webpage, the connect-flash module in Node.js allows developers to display a pop-up message. For example, in your Node.js demo application, you might want to notify\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"Flash messages in Node.js","src":"https:\/\/i2.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":962,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-send-customized-emails-by-integrating-sendgrid-with-a-node-js-application\/","url_meta":{"origin":1525,"position":2},"title":"How to send customized emails by integrating SendGrid with a Node.js application?","date":"May 31, 2022","format":false,"excerpt":"Email is still one of the most popular forms of textual communication, particularly among corporations for notifications, outreach, etc. through their business product. SendGrid is one of the most widely used email APIs to integrate email services into business products. SendGrid makes it simple to send welcome emails, password reset\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"Send Customized emails by SendGrid","src":"https:\/\/i1.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/05\/Cover-Images_Part2-4.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1187,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-upload-single-or-multiple-images-to-a-local-directory-with-multer-in-node-js\/","url_meta":{"origin":1525,"position":3},"title":"How to upload single or multiple images to a local directory with Multer in Node.js?","date":"August 30, 2022","format":false,"excerpt":"The most fundamental operation of any application is a file upload. While images can be uploaded on the front end, they must be received via an API and database on the backend. You can set up file and image uploads in one place using Multer and Express, a Node.js framework.\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"Multer in Node.js","src":"https:\/\/i2.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/08\/Cover-Images_Part2-1-4.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1522,"url":"https:\/\/learning.workfall.com\/learning\/blog\/how-to-connect-to-mongodb-using-mongoose-and-mongodb-atlas-in-node-js\/","url_meta":{"origin":1525,"position":4},"title":"How to connect to MongoDB using Mongoose and MongoDB Atlas in Node.js?","date":"November 29, 2022","format":false,"excerpt":"MongoDB is one of the most popular No-SQL databases in the developer community today. Instead of SQL objects, No-SQL databases allow developers to send and retrieve data as JSON documents. In this blog, we will demonstrate how to connect to MongoDB using Mongoose and MongoDB Atlas in Node.js. Let\u2019s get\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"How to connect to MongoDB using Mongoose and MongoDB Atlas in Node.js?","src":"https:\/\/i1.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/11\/Cover-Images_Part2-1-2.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1397,"url":"https:\/\/learning.workfall.com\/learning\/blog\/pm2-daemon-process-manager-for-a-node-js-application\/","url_meta":{"origin":1525,"position":5},"title":"How to set up a PM2 daemon process manager for a Node.js application?","date":"October 4, 2022","format":false,"excerpt":"Process management encompasses a wide range of activities centered on the creation, termination, and monitoring of processes. A process manager is a program that ensures that your applications remain operational after they have been launched. Process managers can prevent production downtime by restarting your application automatically after a crash or\u2026","rel":"","context":"In &quot;Backend Development&quot;","img":{"alt_text":"How to set up a PM2 daemon process manager for a Node.js application?","src":"https:\/\/i1.wp.com\/learning.workfall.com\/learning\/blog\/wp-content\/uploads\/2022\/10\/Cover-Images_Part2-1.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"_links":{"self":[{"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/posts\/1525"}],"collection":[{"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/comments?post=1525"}],"version-history":[{"count":4,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/posts\/1525\/revisions"}],"predecessor-version":[{"id":2922,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/posts\/1525\/revisions\/2922"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/media\/1526"}],"wp:attachment":[{"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/media?parent=1525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/categories?post=1525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learning.workfall.com\/learning\/blog\/wp-json\/wp\/v2\/tags?post=1525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}