You can secure your API by using API keys, OAuth2, or JWT (JSON Web Tokens). Here's an example of implementing JWT in a Node.js application:
const jwt = require('jsonwebtoken');
const secretKey = 'yourSecretKey';
const token = jwt.sign({ userId: 123 }, secretKey, { expiresIn: '1h' });