-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathserver.js
30 lines (26 loc) · 1 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require('dotenv').config();
const express= require('express')
const app =express()
const routes = require('./routes')
const Web3 = require('web3');
const mongodb = require('mongodb').MongoClient
const contract = require('truffle-contract');
const artifacts = require('./build/Inbox.json');
app.use(express.json())
if (typeof web3 !== 'undefined') {
var web3 = new Web3(web3.currentProvider)
} else {
var web3 = new Web3(new Web3.providers.HttpProvider('http://localhost:8545'))
}
const LMS = contract(artifacts)
LMS.setProvider(web3.currentProvider)
mongodb.connect(process.env.DB,{ useUnifiedTopology: true }, async(err,client)=>{
const db =client.db('Cluster0')
const accounts = await web3.eth.getAccounts();
const lms = await LMS.deployed();
//const lms = LMS.at(contract_address) for remote nodes deployed on ropsten or rinkeby
routes(app,db, lms, accounts)
app.listen(process.env.PORT || 8082, () => {
console.log('listening on port '+ (process.env.PORT || 8082));
})
})