The Movie Database Support

Tmdb api key is not connecting with node.js though i am using this code
export const getNowPlayingMovies = async (req, res)=>{ try { const {data} = await axios.get('https://api.themoviedb.org/3/movie/now_playing', { headers: {Authorization : Bearer ${process.env.TMDB_API_KEY}} }) console.log('TMDB_API_KEY:', process.env.TMDB_API_KEY); const movies = data.results; res.json({success: true, movies: movies}) } catch (error) { console.error(error); res.json({success: false, message: error.message}) } }

4 replies (on page 1 of 1)

Jump to last post

@DimpleChoudhary said:
why tmdb api key is not connecting with nodejs
Tmdb api key is not connecting with node.js though i am using this code

export const getNowPlayingMovies = async (req, res)=>{ 
    try {
        const {data} = await axios.get('https://api.themoviedb.org/3/movie/now_playing', {
            headers: {Authorization : `Bearer ${process.env.TMDB_API_KEY}`}
        })
        console.log('TMDB_API_KEY:', process.env.TMDB_API_KEY);
        const movies = data.results;
        res.json({success: true, movies: movies})
    } catch (error) {
        console.error(error);
        res.json({success: false, message: error.message})
    }
}

Have you tried using your "TMDB_API_TOKEN" instead of "TMDB_API_KEY"?

Your API Read Access Token can be found here:
https://www.themoviedb.org/settings/api
Or here:
https://developer.themoviedb.org/reference/intro/getting-started

Yes currently i am using tmdb_api_token just i named it like this for my ease. Nothing is working please help me out.

Did you receive an Error Message?
Copy and paste here the entire text of the message.

{ "success": false, "message": "Client network socket disconnected before secure TLS connection was established" }

This is what i am getting on postman.

[nodemon] starting node server.js Database connected Server listening at http://localhost:3000 AxiosError: Client network socket disconnected before secure TLS connection was established at AxiosError.from (/movie-ticket-booking-app/server/node_modules/axios/lib/core/AxiosError.js:92:14)
at RedirectableRequest.handleRequestError (/movie-ticket-booking-app/server/node_modules/axios/lib/adapters/http.js:620:25) at RedirectableRequest.emit (node:events:518:28) at eventHandlers. (\movie-ticket-booking-app\server\node_modules\follow-redirects\index.js:49:24) at ClientRequest.emit (node:events:518:28) at emitErrorEvent (node:_http_client:104:11) at TLSSocket.socketErrorListener (node:_http_client:518:5) at TLSSocket.emit (node:events:518:28) at emitErrorNT (node:internal/streams/destroy:170:8) at emitErrorCloseNT (node:internal/streams/destroy:129:3) at Axios.request (file:///E:/movie-ticket-booking-app/server/node_modules/axios/lib/core/Axios.js:45:41) at process.processTicksAndRejections (node:internal/process/task_queues:105:5) at async getNowPlayingMovies (:/movie-ticket-booking-app/server/controllers/showController.js:7:24) { localAddress: undefined, port: 443, host: 'api.themoviedb.org', path: null, code: 'ECONNRESET', config: { transitional: { silentJSONParsing: true, forcedJSONParsing: true, clarifyTimeoutError: false }, adapter: [ 'xhr', 'http', 'fetch' ], transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, env: { FormData: [Function [FormData]], Blob: [class Blob] }, validateStatus: [Function: validateStatus], headers: Object [AxiosHeaders] { Accept: 'application/json, text/plain, /', 'Content-Type': undefined, Authorization: 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJ.............', 'User-Agent': 'axios/1.11.0', 'Accept-Encoding': 'gzip, compress, deflate, br' }, method: 'get', url: 'https://api.themoviedb.org/3/movie/now_playing', allowAbsoluteUrls: true, data: undefined }, request: Writable { _events: { close: undefined, error: [Function: handleRequestError], prefinish: undefined, finish: undefined, drain: undefined, response: [Function: handleResponse], socket: [Function: handleRequestSocket] }, _writableState: WritableState { highWaterMark: 16384, length: 0, corked: 0, onwrite: [Function: bound onwrite], writelen: 0, bufferedIndex: 0, pendingcb: 0, [Symbol(kState)]: 17580812, [Symbol(kBufferedValue)]: null }, _maxListeners: undefined, _options: { maxRedirects: 21, maxBodyLength: Infinity, protocol: 'https:', path: '/3/movie/now_playing', method: 'GET', headers: [Object: null prototype], agents: [Object], auth: undefined, family: undefined, beforeRedirect: [Function: dispatchBeforeRedirect], beforeRedirects: [Object], hostname: 'api.themoviedb.org', port: '', agent: undefined, nativeProtocols: [Object], pathname: '/3/movie/now_playing' }, _ended: true, _ending: true, _redirectCount: 0, _redirects: [], _requestBodyLength: 0, _requestBodyBuffers: [], _eventsCount: 3, _onNativeResponse: [Function (anonymous)], _currentRequest: ClientRequest { _events: [Object: null prototype], _eventsCount: 7, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, destroyed: false, _last: true, chunkedEncoding: false, shouldKeepAlive: true, maxRequestsOnConnectionReached: false, _defaultKeepAlive: true, useChunkedEncodingByDefault: false, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, strictContentLength: false, _contentLength: 0, _hasBody: true, _trailer: '', finished: true, _headerSent: true, _closed: false, _header: 'GET /3/movie/now_playing HTTP/1.1\r\n' + 'Accept: application/json, text/plain, /\r\n' + 'Authorization: Bearer eyJhbGciOiJIUzI1Ni...........\r\n' + 'User-Agent: axios/1.11.0\r\n' + 'Accept-Encoding: gzip, compress, deflate, br\r\n' + 'Host: api.themoviedb.org\r\n' + 'Connection: keep-alive\r\n' + '\r\n', _keepAliveTimeout: 0, _onPendingData: [Function: nop], agent: [Agent], socketPath: undefined, method: 'GET', maxHeaderSize: undefined, insecureHTTPParser: undefined, joinDuplicateHeaders: undefined, path: '/3/movie/now_playing', _ended: false, res: null, aborted: false, timeoutCb: [Function: emitRequestTimeout], upgradeOrConnect: false, parser: null, maxHeadersCount: null, reusedSocket: false, host: 'api.themoviedb.org', protocol: 'https:', _redirectable: [Circular *1], [Symbol(shapeMode)]: false, [Symbol(kCapture)]: false, [Symbol(kBytesWritten)]: 0, [Symbol(kNeedDrain)]: false, [Symbol(corked)]: 0, [Symbol(kChunkedBuffer)]: [], [Symbol(kChunkedLength)]: 0, [Symbol(kSocket)]: [TLSSocket], [Symbol(kOutHeaders)]: [Object: null prototype], [Symbol(errored)]: null, [Symbol(kHighWaterMark)]: 16384, [Symbol(kRejectNonStandardBodyWrites)]: false, [Symbol(kUniqueHeaders)]: null }, _currentUrl: 'https://api.themoviedb.org/3/movie/now_playing', [Symbol(shapeMode)]: true, [Symbol(kCapture)]: false }, cause: Error: Client network socket disconnected before secure TLS connection was established at TLSSocket.onConnectEnd (node:_tls_wrap:1732:19) at TLSSocket.emit (node:events:530:35) at endReadableNT (node:internal/streams/readable:1698:12) at process.processTicksAndRejections (node:internal/process/task_queues:90:21) { code: 'ECONNRESET', path: null, host: 'api.themoviedb.org', port: 443, localAddress: undefined } }

This is what i am getting on vscode. Please help me.

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login