最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular 2 and SQLite connection - Stack Overflow

programmeradmin6浏览0评论

I have done some Angular 2 for the first time and after the html and css I now am stuck at the DB connection.
Here is what I am working with:

  1. appponent.ts (Loads the templateURL)
  2. overviewponent.html (Is the template, 90% html 10% Modal)
  3. db_basic.db (The DB File)
  4. sql.js (This can get Values of the db if you do node sql.js)

Here the sql.js file to show how I can connect to the DB.

var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('../db/db_basic.db');
var check;
db.serialize(function() {
    db.each("SELECT * FROM server", function(err, row) {
        console.log(row.name);
    });
});
db.close();


Now, my Question would be, how do I connect to the DB and use those values in the HTML?

Extra:

I have done some Angular 2 for the first time and after the html and css I now am stuck at the DB connection.
Here is what I am working with:

  1. app.ponent.ts (Loads the templateURL)
  2. overview.ponent.html (Is the template, 90% html 10% Modal)
  3. db_basic.db (The DB File)
  4. sql.js (This can get Values of the db if you do node sql.js)

Here the sql.js file to show how I can connect to the DB.

var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('../db/db_basic.db');
var check;
db.serialize(function() {
    db.each("SELECT * FROM server", function(err, row) {
        console.log(row.name);
    });
});
db.close();


Now, my Question would be, how do I connect to the DB and use those values in the HTML?

Extra:

Share Improve this question asked Aug 11, 2016 at 7:21 BonoBono 1812 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You need to make a rest API.

The rest API seperates frontend (angular) from backend (database), it serves you data and it can take care of security.

You can use a framework such as express.js to make a rest API in node.

Express.js can also be used to serve your static files (angular project) (so you do not need appache or nginx).

发布评论

评论列表(0)

  1. 暂无评论