Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

Share this Page URL
Help

Hour 8. Persisting Data > Using Databases - Pg. 108

108 HOUR 8: Persisting Data 3. Run the script: node app.js 4. You should see c6YFPvdT7Yh3JAFW62EBa5LDe4X printed to the terminal. Using Databases The examples in this hour have shown how to set and retrieve small amounts of data using files or environment variables. If you are creating web applications with Node.js, you will definitely want to use a database or data store at some point. Some of the scenarios that you need a data- base for include Allowing users to save information Allowing users to create, read, update, and delete records Creating a web service, or API, from your data Node.js has good support for most major databases, so which one should you use? Relational Databases You may have had exposure to some of the following relational databases: MySQL PostgresSQL Oracle Microsoft SQL Server SQLite Relational databases store data in separate tables and create relationships between tables using primary and foreign keys. Let's say you have a blogging application with a database including tables for blog posts and comments. Using primary and foreign keys within the tables, it is easy to write queries for things like The last 10 blog posts in date order All of the comments for a blog post All blog posts between two moments in time