Advertisement
ngekoding

ASK - Node.js lifecycle

Mar 7th, 2021
1,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require('express');
  2. const http = require('http');
  3. const { Client } = require('pg');
  4.  
  5. const app = express();
  6. const server = http.createServer(app);
  7.  
  8. // Connect and get data from DB
  9. const client = new Client({
  10.   connectionString: '<CONNECTION>'
  11. });
  12.  
  13. client.connect();
  14.  
  15. client.query('SELECT * FROM tb_name', function(err, results) {
  16.   // Results
  17. });
  18.  
  19. // Creating object that accept options from DB
  20. const object = new MyObject({ optionFromDB });
  21.  
  22. object.on('ready', () => {
  23.   // Do something when ready
  24. });
  25.  
  26. server.listen(8000);
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement