-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
40 lines (35 loc) · 998 Bytes
/
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
31
32
33
34
35
36
37
38
39
40
const express = require('express');
const Twitter = require('twit');
const app = express();
const path = require('path');
const PORT = 4000;
const HOST = '0.0.0.0'
const client = new Twitter({
consumer_key: '',
consumer_secret: '',
access_token: '',
access_token_secret: ''
});
app.use(require('cors')());
app.use(require('body-parser').json());
app.get('/', (req, res) => {
// res.send('Server running');
res.sendFile(path.join(__dirname, 'index.html'));
});
app.get('/exists/:name', (req, res) => {
const params = { screen_name: req.params.name };
// console.log(req.params.name)
client
.get('users/lookup', params)
.then(response => {
res.send(response.data);
// console.log('response', response)
})
.catch(error => {
res.status(error.statusCode).send(error);
// console.log('error', error)
});
});
app.listen(process.env.PORT || PORT, function(){
console.log('Your node js server is running');
});